@@ -157,7 +157,7 @@ platform_launch(void)
157157 pthread_key_create (& tidkey , NULL );
158158}
159159
160- #endif
160+ #endif /* pthread threading */
161161
162162/* Win Thread */
163163#ifdef NUMBA_WINTHREAD
@@ -262,7 +262,7 @@ platform_launch(void)
262262 tidkey = TlsAlloc ();
263263}
264264
265- #endif
265+ #endif /* Windows threading */
266266
267267typedef struct Task
268268{
@@ -321,12 +321,20 @@ static THREAD_LOCAL(int) _TLS_num_threads = 0;
321321static void
322322set_num_threads (int count )
323323{
324+ if (!queues )
325+ {
326+ launch_threads (NUM_THREADS );
327+ }
324328 _TLS_num_threads = count ;
325329}
326330
327331static int
328332get_num_threads (void )
329333{
334+ if (!queues )
335+ {
336+ launch_threads (NUM_THREADS );
337+ }
330338 // This is purely to permit the implementation to survive to the point
331339 // where it can exit cleanly as multiple threads cannot be used with this
332340 // backend
@@ -506,6 +514,11 @@ add_task_internal(void *fn, void *args, void *dims, void *steps, void *data, int
506514{
507515 void (* func )(void * args , void * dims , void * steps , void * data ) = fn ;
508516
517+ if (!queues )
518+ {
519+ launch_threads (NUM_THREADS );
520+ }
521+
509522 Queue * queue = & queues [queue_pivot ];
510523
511524 Task * task = & queue -> task ;
@@ -581,6 +594,11 @@ static void launch_threads(int count)
581594
582595static void synchronize (void )
583596{
597+ // This probably isn't needed, but is put in as a guard
598+ if (!queues )
599+ {
600+ launch_threads (NUM_THREADS );
601+ }
584602 int i ;
585603 for (i = 0 ; i < queue_count ; ++ i )
586604 {
@@ -590,6 +608,11 @@ static void synchronize(void)
590608
591609static void ready (void )
592610{
611+ // This probably isn't needed, but is put in as a guard
612+ if (!queues )
613+ {
614+ launch_threads (NUM_THREADS );
615+ }
593616 int i ;
594617 for (i = 0 ; i < queue_count ; ++ i )
595618 {
@@ -601,8 +624,10 @@ static void reset_after_fork(void)
601624{
602625 free (queues );
603626 queues = NULL ;
604- NUM_THREADS = -1 ;
605- _INIT_NUM_THREADS = -1 ;
627+ if (_INIT_NUM_THREADS != -1 )
628+ {
629+ NUM_THREADS = _INIT_NUM_THREADS ;
630+ }
606631 _nesting_level = 0 ;
607632}
608633
0 commit comments