C++11 Thread safety of Random number generators

The C++11 standard library is broadly thread safe. The thread safety guarantees on PRNG objects are the same as on containers. More specifically, since the PRNG classes are all pseudo-random, i.e. they generate a deterministic sequence based on a definite current state, there is really no room to be peeking or poking at anything outside … Read more

iOS GCD: Difference between any global queue and the one with background priority (DISPATCH_QUEUE_PRIORITY_BACKGROUND)?

This is explained pretty well in the dispatch/queue.h header: DISPATCH_QUEUE_PRIORITY_HIGH Items dispatched to the queue will run at high priority, i.e. the queue will be scheduled for execution before any default priority or low priority queue. DISPATCH_QUEUE_PRIORITY_DEFAULT Items dispatched to the queue will run at the default priority, i.e. the queue will be scheduled for … Read more

How can I replace deprecated method dispatch_get_current_queue()? [duplicate]

It depends what you need to achieve with this call. Apple states that it should be used for debugging anyway. Perhaps the queue does not matter (as you just need a background queue) so get a global queue with specific priority (dispatch_get_global_queue(dispatch_queue_priority_t priority, unsigned long flags);) OR, If you do need to execute some pieces … Read more

Wait for async task to finish completion block before returning in app delegate

I’m unsure why the didFinishLaunching return status is dependent upon the success of your completion handler as you’re not apparently even considering launchOptions. I’d hate to see you put an synchronous call (or more accurately, use a semaphore to convert an asynchronous method into a synchronous one) here, as it will slow down the app … Read more

How can I verify that I am running on a given GCD queue without using dispatch_get_current_queue()?

Assign whatever identifier you want using dispatch_queue_set_specific(). You can then check your identifier using dispatch_get_specific(). Remember that dispatch_get_specific() is nice because it’ll start at the current queue, and then walk up the target queues if the key isn’t set on the current one. This usually doesn’t matter, but can be useful in some cases.

What property should I use for a Dispatch Queue after ARC?

Updated answer: In current OS X and iOS, Dispatch objects are now treated as Obj-C objects by ARC. They will be memory-managed the same way that Obj-C objects will, and you should use strong for your property. This is controlled by the OS_OBJECT_USE_OBJC macro, defined in <os/object.h>. It’s set to 1 by default when your … Read more

Core Data and threads / Grand Central Dispatch

Here’s a good example for you to try. Feel free to come back if you have any questions: self.mainThreadContext… // This is a reference to your main thread context NSPersistentStoreCoordinator *mainThreadContextStoreCoordinator = [self.mainThreadContext persistentStoreCoordinator]; dispatch_queue_t request_queue = dispatch_queue_create(“com.yourapp.DescriptionOfMethod”, NULL); dispatch_async(request_queue, ^{ // Create a new managed object context // Set its persistent store coordinator NSManagedObjectContext … Read more

Using dispatch_async with self

You should condition spinning off this action on the non-nullity, not test for it after you’ve already initiated it: if let hostView = self.hostViewController?.view { DispatchQueue.main.async { hostView.addSubview(self.commandField) } } else { // handle nil hostView } You should never unwrap an optional outside of an if let, or testing it first. Doing this should … Read more

What is the difference between dispatch_get_global_queue and dispatch_queue_create?

As the documentation describes, a global queue is good for concurrent tasks (i.e. you’re going to dispatch various tasks asynchronously and you’re perfectly happy if they run concurrently) and if you don’t want to encounter the theoretical overhead of creating and destroying your own queue. The creating of your own queue is very useful if … Read more

What’s the difference between performSelectorOnMainThread: and dispatch_async() on main queue?

By default, -performSelectorOnMainThread:withObject:waitUntilDone: only schedules the selector to run in the default run loop mode. If the run loop is in another mode (e.g. the tracking mode), it won’t run until the run loop switches back to the default mode. You can get around this with the variant -performSelectorOnMainThread:withObject:waitUntilDone:modes: (by passing all the modes you … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)