From 80e6061ac5deca193759b979d34906bfc9b857ef Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Wed, 13 Feb 2002 09:32:52 +0000 Subject: Several test suite updates. The testatexit, teston_exit, and pthread tests were contributed by Stefan Soucek --- test/pthread/ex3.c | 152 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 test/pthread/ex3.c (limited to 'test/pthread/ex3.c') diff --git a/test/pthread/ex3.c b/test/pthread/ex3.c new file mode 100644 index 000000000..8005200ef --- /dev/null +++ b/test/pthread/ex3.c @@ -0,0 +1,152 @@ +/* Multi-thread searching. + Illustrates: thread cancellation, cleanup handlers. */ + +#include +#include +#include +#include +#include +#include + +/* Defines the number of searching threads */ +#define NUM_THREADS 5 + +/* Function prototypes */ +void *search(void *); +void print_it(void *); + +/* Global variables */ +pthread_t threads[NUM_THREADS]; +pthread_mutex_t lock; +int tries; +volatile int started; + +int main(int argc, char ** argv) +{ + int i; + int pid; + + /* create a number to search for */ + pid = getpid(); + printf("Searching for the number = %d...\n", pid); + + /* Initialize the mutex lock */ + pthread_mutex_init(&lock, NULL); + + /* Create the searching threads */ + for (started=0; started