@@ -111,24 +111,6 @@ class os_thread {
111111 return ;
112112 }
113113 }
114- \
115- err = pthread_create (&thread, &attrib, ThreadTrampoline, args.get ());
116-
117- // Probably a stack size error since system limits can be different from PTHREAD_STACK_MIN
118- // Attempt to grow the stack within reason.
119- if ((err == EINVAL) && stackSize != 0 ) {
120- while (stackSize < 20 * 1024 * 1024 ) {
121- stackSize *= 2 ;
122- err = pthread_attr_setstacksize (&attrib, stackSize);
123- if (err != 0 ) {
124- fprintf (stderr, " pthread_attr_setstacksize failed: %s\n " , strerror (err));
125- return ;
126- }
127- err = pthread_create (&thread, &attrib, ThreadTrampoline, args.get ());
128- if (err != EINVAL) break ;
129- debug_print (" pthread_create returned EINVAL, doubling stack size\n " );
130- }
131- }
132114
133115 if (core::Runtime::runtime_singleton_->flag ().override_cpu_affinity ()) {
134116 int cores = get_nprocs_conf ();
@@ -141,14 +123,32 @@ class os_thread {
141123 for (int i = 0 ; i < cores; i++) {
142124 CPU_SET_S (i, CPU_ALLOC_SIZE (cores), cpuset);
143125 }
144- err = pthread_setaffinity_np (thread , CPU_ALLOC_SIZE (cores), cpuset);
126+ err = pthread_attr_setaffinity_np (&attrib , CPU_ALLOC_SIZE (cores), cpuset);
145127 CPU_FREE (cpuset);
146128 if (err != 0 ) {
147129 fprintf (stderr, " pthread_attr_setaffinity_np failed: %s\n " , strerror (err));
148130 return ;
149131 }
150132 }
151133
134+ err = pthread_create (&thread, &attrib, ThreadTrampoline, args.get ());
135+
136+ // Probably a stack size error since system limits can be different from PTHREAD_STACK_MIN
137+ // Attempt to grow the stack within reason.
138+ if ((err == EINVAL) && stackSize != 0 ) {
139+ while (stackSize < 20 * 1024 * 1024 ) {
140+ stackSize *= 2 ;
141+ err = pthread_attr_setstacksize (&attrib, stackSize);
142+ if (err != 0 ) {
143+ fprintf (stderr, " pthread_attr_setstacksize failed: %s\n " , strerror (err));
144+ return ;
145+ }
146+ err = pthread_create (&thread, &attrib, ThreadTrampoline, args.get ());
147+ if (err != EINVAL) break ;
148+ debug_print (" pthread_create returned EINVAL, doubling stack size\n " );
149+ }
150+ }
151+
152152 if (err == 0 )
153153 args.release ();
154154 else
0 commit comments