/* * Copyright 2002-2019 Intel Corporation. * * This software is provided to you as Sample Source Code as defined in the accompanying * End User License Agreement for the Intel(R) Software Development Products ("Agreement") * section 1.L. * * This software and the related documents are provided as is, with no express or implied * warranties, other than those that are expressly stated in the License. */ #include #include #include #include #include #include pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER; void *threadMain(void *arg) { fprintf(stderr, "In second thread: starting\n"); pthread_mutex_lock(&mtx); pthread_mutex_lock(&mtx); /* we should not get here */ assert(0); } int main() { struct sigaction act; pthread_t thd; int i; /* make poke signal restartable to reproduce mantis: 4073 */ for (i = 1; i < NSIG; i++) { sigaction(i, 0, &act); act.sa_flags |= SA_RESTART; sigaction(i, &act, 0); } pthread_create(&thd, NULL, &threadMain, 0); fprintf(stderr, "In the main thread: Waiting for second thread to be ready\n"); /* wait for the thread to be ready */ while (1) { sleep(1); if (0 == pthread_mutex_trylock(&mtx)) { pthread_mutex_unlock(&mtx); } else { // First pthread_mutex_lock in the other thread was executed. break; } } /* wait three more seconds to make sure the thread is blocked in the second pthread_mutex_lock */ sleep(3); fprintf(stderr, "In the main thread: Exiting\n"); exit(0); }