Skip to content

Commit

Permalink
Fix signal_handler_run_in_c_thread test (#2701)
Browse files Browse the repository at this point in the history
  • Loading branch information
stedolan authored Jun 19, 2024
1 parent cbd5e54 commit 21858fd
Showing 1 changed file with 10 additions and 2 deletions.
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 21858fd

Please sign in to comment.