Skip to content

Instantly share code, notes, and snippets.

@deadtrickster
Created October 9, 2016 19:23
Show Gist options
  • Save deadtrickster/5a92841276f3d069b58f5cdd2128ec9c to your computer and use it in GitHub Desktop.
Save deadtrickster/5a92841276f3d069b58f5cdd2128ec9c to your computer and use it in GitHub Desktop.
/* stop all other threads by sending them SIG_STOP_FOR_GC */
for(p=all_threads; p; p=p->next) {
gc_assert(p->os_thread != 0);
FSHOW_SIGNAL((stderr,"/gc_stop_the_world: thread=%lu, state=%x\n",
p->os_thread, thread_state(p)));
if((p!=th) && ((thread_state(p)==STATE_RUNNING))) {
FSHOW_SIGNAL((stderr,"/gc_stop_the_world: suspending thread %lu\n",
p->os_thread));
/* We already hold all_thread_lock, P can become DEAD but
* cannot exit, ergo it's safe to use pthread_kill. */
status=pthread_kill(p->os_thread,SIG_STOP_FOR_GC);
if (status==ESRCH) {
/* This thread has exited. */
gc_assert(thread_state(p)==STATE_DEAD);
} else if (status) {
lose("cannot send suspend thread=%lu: %d, %s\n",
p->os_thread,status,strerror(status));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment