Skip to content

Commit

Permalink
flambda-backend: Fix signal_handler_run_in_c_thread test (ocaml-flamb…
Browse files Browse the repository at this point in the history
  • Loading branch information
stedolan authored Jun 19, 2024
1 parent f8bc8fd commit 4c0a469
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions testsuite/tests/lib-threads/signal_handler_run_in_c_thread_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@

static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static int thread_started = 0;

static void* in_thread(void* unused)
{
(void) pthread_cond_signal(&cond);
pthread_mutex_lock(&mutex);
thread_started = 1;
pthread_cond_signal(&cond);
pthread_mutex_unlock(&mutex);
/* Signal to be received in this thread by the OCaml signal handler */
while (1);
}
Expand All @@ -16,7 +20,11 @@ value test_signal_handler_run_in_c_thread(value unit)
{
pthread_t thread;
pthread_create(&thread, NULL, &in_thread, NULL);
pthread_cond_wait(&cond, &mutex);
pthread_mutex_lock(&mutex);
while (!thread_started) {
pthread_cond_wait(&cond, &mutex);
}
pthread_mutex_unlock(&mutex);
pthread_kill(thread, SIGUSR1);
return Val_unit;
}

0 comments on commit 4c0a469

Please sign in to comment.