I have 5 functions that need to be run on a separate thread. Grand Central Dispatch is supposed to be more efficient than threads so I decided to use it. Each function has an infinite while loop – while(true)– that runs throughout the duration of the program. So the function doesn’t return until the program exists. The thing is though, GCD doesn’t run queues at the same time – it runs each queu one at a time. When the first queu completes, it begins the second queu. If I put each function on a queue, only one will run because Grand Central Dispatch will be waiting for the first one to return to run the next one but the function will never return (since it is an infinite while loop). Is there any way I can use GCD with infinite loop functions? Or should I just use threads?
Xcode 3.2.6 on Mac OSX Snowleopard 10.6.8.
Sounds to me like you are using dispatch_sync. Have a look at dispatch_async.
https://developer.apple.com/library/mac/documentation/Performance/Reference/GCD_libdispatch_Ref/Reference/reference.html#//apple_ref/c/func/dispatch_async
It returns immediately, and you can launch multiple queues simultaneously, each function in a separate queue.