Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSPrivateQueueConcurrencyType serial or concurrent?

As the title says, the question is, if a NSManagedObjectContext with concurrency type NSPrivateQueueConcurrencyType is serial or concurrent.

More specifically, if I call

[managedObjectContext performBlock:^{

}];

with a long running task, will other calls to that context with performBlock be blocked until the first one finished?

like image 771
Kevin Flachsmann Avatar asked Dec 23 '22 17:12

Kevin Flachsmann


1 Answers

It is serial queue from Apple docs.

Or you can simply try to run this code and see the result. The numbers will be printed serially.

    let privateMOC = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
    privateMOC.perform {
        for i in 0...8000 {
            if i.isMultiple(of: 3000) {
                print("1")
            }
        }
    }
    privateMOC.perform {
        for i in 0...8000 {
            if i.isMultiple(of: 3000) {
                print("2")
            }
        }
    }
like image 101
nhatduy Avatar answered Dec 28 '22 10:12

nhatduy