[libdispatch-dev] libdispatch's thread model

Mario Schwalbe schwalbe at inf.tu-dresden.de
Wed Jan 27 08:01:41 PST 2010


Hi,

On 27.01.2010 16:41, Mario Schwalbe wrote:
> I know that Apple's non-posix extension to pthread isn't available.
> Nevertheless, it should be possible to at least use a bounded number of
> worker threads less than MAX_THREAD_COUNT (255). What about dynamically
> setting MAX_THREAD_COUNT (or a similar variable) to the number of
> processors  instead?

As it turns out, the patch is rather simple:

Index: queue.c
===================================================================
--- queue.c	(Revision 181)
+++ queue.c	(Arbeitskopie)
@@ -1188,6 +1188,8 @@
  			if (r != ENOTSUP) {
  				(void)dispatch_assume_zero(r);
  			}
+#else  /* HAVE_PTHREAD_WORKQUEUES */
+		_dispatch_root_queue_contexts[i].dgq_thread_pool_size = _dispatch_hw_config.cc_max_active;
  #endif /* HAVE_PTHREAD_WORKQUEUES */
  #if USE_MACH_SEM
  			// override the default FIFO behavior for the pool semaphores

There's similar code in _dispatch_root_queues_init() for the implementation
using pthread workqueues, but disabled. Why?

ciao,
Mario



More information about the libdispatch-dev mailing list