I have a class at http://ift.tt/1y4SKHy that I am trying to make sure is thread safe.
I have a queue called _dbQueue
private let _dbQueue = dispatch_queue_create("com.AaronLBratcher.ALBNoSQLDBQueue", nil)
and I open the db synchronously on this queue
...
var openDBSuccessful = true
//create task closure
let openFile:() = {
openDBSuccessful = self.openDBFile(dbFilePath)
}()
dispatch_sync(_dbQueue) {
openFile
}
...
I also run commands and queries synchronously on the same queue
private func sqlExecute(sql:String)->Bool {
var successful = true
//create task closure
let command:() = {
successful = self.runCommand(sql)
}()
dispatch_sync(_dbQueue) {
command
}
return successful
}
func sqlSelect(sql:String)->[DBRow]? { // DBRow is an array of AnyObject
var recordset:[DBRow]?
let query:() = {
recordset = self.runSelect(sql)
}()
dispatch_sync(_dbQueue) {
query
}
return recordset
}
When doing some testing however, I got this. How do I guarantee calls on the same thread to the sqlite db?
Aucun commentaire:
Enregistrer un commentaire