views:

74

answers:

1

I am using C and Grand Central Dispatch to parallelize some heavy computations. How can I get the number of threads used by GCD? Also is it possible to know on which thread a piece of code is currently running on? Basically I'd like to use sprng (parallel random numbers) with multiple streams and for that I need to know what stream id to use (and therefore what thread is being used).

A: 
  • as each thread has a different runloop you can get the current runloop by CFRunLoopGetCurrent()
  • or if you're using AppKit [NSThread currentThread];
  • on NSThread you can add any other object to share between calls on the same thread using - (NSMutableDictionary *)threadDictionary
  • or you can work on pthread API man pthread
mahal tertin