Files
linux-kernel-module-cheat/userland/posix/pthread_deadlock.c
Ciro Santilli 六四事件 法轮功 d7a24ea200 start moving malloc and friends in
2019-08-11 00:00:00 +00:00

29 lines
687 B
C

/* Let's see a trivial deadlock in action to feel the joys of multithreading.
*
* https://cirosantilli.com/linux-kernel-module-cheat#pthreads
*
* Exit successfully immediately without any arguments:
*
* ./pthread_deadlock.out
*
* Hang forever in a deadlock if one argument is given:
*
* ....
* ./pthread_deadlock.out 0
* ....
*/
#define _XOPEN_SOURCE 700
#include <assert.h>
#include <pthread.h>
#include <stdlib.h>
int main(int argc, char **argv) {
pthread_mutex_t main_thread_mutex = PTHREAD_MUTEX_INITIALIZER;
(void)(argv);
pthread_mutex_lock(&main_thread_mutex);
if (argc > 1)
pthread_mutex_lock(&main_thread_mutex);
return EXIT_SUCCESS;
}