| 317 | }; |
| 318 | |
| 319 | static void* ThreadMain(void* argument) { |
| 320 | ThreadInfo* thread_info = static_cast<ThreadInfo*>(argument); |
| 321 | const ScopedSetThreadName scoped_set_thread_name(thread_info->thread_name); |
| 322 | |
| 323 | pthread_t thread = pthread_self(); |
| 324 | thread_info->stack_base = |
| 325 | FromPointerCast<mach_vm_address_t>(pthread_get_stackaddr_np(thread)); |
| 326 | thread_info->stack_size = pthread_get_stacksize_np(thread); |
| 327 | |
| 328 | thread_info->ready_semaphore.Signal(); |
| 329 | thread_info->exit_semaphore.Wait(); |
| 330 | |
| 331 | // Check this here after everything’s known to be synchronized, otherwise |
| 332 | // there’s a race between the parent thread storing this thread’s pthread_t |
| 333 | // in thread_info_pthread and this thread starting and attempting to access |
| 334 | // it. |
| 335 | CHECK_EQ(pthread_self(), thread_info->pthread); |
| 336 | |
| 337 | return nullptr; |
| 338 | } |
| 339 | |
| 340 | // This is a vector of pointers because the address of a ThreadInfo object is |
| 341 | // passed to each thread’s ThreadMain(), so they cannot move around in memory. |