@@ -778,9 +778,9 @@ void jl_init_threading(void)
778778 }
779779
780780 jl_all_tls_states_size = nthreads + nthreadsi + ngcthreads ;
781- jl_n_threads_per_pool = (int * )malloc_s (2 * sizeof (int ));
782- jl_n_threads_per_pool [0 ] = nthreadsi ;
783- jl_n_threads_per_pool [1 ] = nthreads ;
781+ jl_n_threads_per_pool = (int * )malloc_s (jl_n_threadpools * sizeof (int ));
782+ jl_n_threads_per_pool [JL_THREADPOOL_ID_INTERACTIVE ] = nthreadsi ;
783+ jl_n_threads_per_pool [JL_THREADPOOL_ID_DEFAULT ] = nthreads ;
784784 assert (jl_all_tls_states_size > 0 );
785785 jl_atomic_store_release (& jl_all_tls_states , (jl_ptls_t * )calloc (jl_all_tls_states_size , sizeof (jl_ptls_t )));
786786 jl_atomic_store_release (& jl_n_threads , jl_all_tls_states_size );
@@ -793,9 +793,9 @@ uv_barrier_t thread_init_done;
793793void jl_start_threads (void )
794794{
795795 int nthreads = jl_atomic_load_relaxed (& jl_n_threads );
796- int ngcthreads = jl_n_gcthreads ;
797- int nthreadsi = jl_n_threads_per_pool [0 ];
798- int nmutator_threads = nthreads - ngcthreads ;
796+ int ninteractive_threads = jl_n_threads_per_pool [ JL_THREADPOOL_ID_INTERACTIVE ] ;
797+ int ndefault_threads = jl_n_threads_per_pool [JL_THREADPOOL_ID_DEFAULT ];
798+ int nmutator_threads = nthreads - jl_n_gcthreads ;
799799
800800 int cpumasksize = uv_cpumask_size ();
801801 char * cp ;
@@ -811,17 +811,19 @@ void jl_start_threads(void)
811811 if (cp && strcmp (cp , "0" ) != 0 )
812812 exclusive = 1 ;
813813
814- // exclusive use: affinitize threads, master thread on proc 0, rest
815- // according to a 'compact' policy
814+ // exclusive use: affinitize threads, master thread on proc 0, threads in
815+ // default pool according to a 'compact' policy
816816 // non-exclusive: no affinity settings; let the kernel move threads about
817817 if (exclusive ) {
818- if (nmutator_threads - nthreadsi > jl_cpu_threads ()) {
818+ if (ndefault_threads > jl_cpu_threads ()) {
819819 jl_printf (JL_STDERR , "ERROR: Too many threads requested for %s option.\n" , MACHINE_EXCLUSIVE_NAME );
820820 exit (1 );
821821 }
822822 memset (mask , 0 , cpumasksize );
823823
824- if (nthreadsi == 0 ) {
824+ // If there are no interactive threads, the master thread is in the
825+ // default pool and we must affinitize it
826+ if (ninteractive_threads == 0 ) {
825827 mask [0 ] = 1 ;
826828 uvtid = uv_thread_self ();
827829 uv_thread_setaffinity (& uvtid , mask , NULL , cpumasksize );
@@ -838,10 +840,13 @@ void jl_start_threads(void)
838840 t -> tid = i ;
839841 t -> barrier = & thread_init_done ;
840842 uv_thread_create (& uvtid , jl_threadfun , t );
841- if (exclusive && i > nthreadsi ) {
842- mask [i - nthreadsi ] = 1 ;
843+
844+ // Interactive pool threads get the low IDs, so check if this is a
845+ // default pool thread. The master thread is already on CPU 0.
846+ if (exclusive && i >= ninteractive_threads ) {
847+ mask [i - ninteractive_threads ] = 1 ;
843848 uv_thread_setaffinity (& uvtid , mask , NULL , cpumasksize );
844- mask [i - nthreadsi ] = 0 ;
849+ mask [i - ninteractive_threads ] = 0 ;
845850 }
846851 uv_thread_detach (& uvtid );
847852 }
0 commit comments