diff options
| author | Armin Rigo <arigo@tunes.org> | 2016-01-01 11:36:17 +0100 |
|---|---|---|
| committer | Armin Rigo <arigo@tunes.org> | 2016-01-01 11:36:17 +0100 |
| commit | 879c92d0093f8d24da49d45abf76204f48548ffe (patch) | |
| tree | 437953c1c2f9a8b826f22063b5bb9e88263899bb /testing/embedding/thread1-test.c | |
| parent | fc90431d8dc8df0af1dd0367eeee8bb76c36168f (diff) | |
| download | cffi-879c92d0093f8d24da49d45abf76204f48548ffe.tar.gz | |
test multiple threads all doing the initial call to an "extern Python"
function in parallel
Diffstat (limited to 'testing/embedding/thread1-test.c')
| -rw-r--r-- | testing/embedding/thread1-test.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/testing/embedding/thread1-test.c b/testing/embedding/thread1-test.c new file mode 100644 index 0000000..9cde9eb --- /dev/null +++ b/testing/embedding/thread1-test.c @@ -0,0 +1,43 @@ +#include <stdio.h> +#include <pthread.h> +#include <semaphore.h> +#include <assert.h> + +#define NTHREADS 10 + + +extern int add1(int, int); + +static sem_t done; + + +static void *start_routine(void *arg) +{ + int x, y, status; + x = add1(40, 2); + assert(x == 42); + + status = sem_post(&done); + assert(status == 0); + + return arg; +} + +int main(void) +{ + pthread_t th; + int i, status = sem_init(&done, 0, 0); + assert(status == 0); + + printf("starting\n"); + for (i = 0; i < NTHREADS; i++) { + status = pthread_create(&th, NULL, start_routine, NULL); + assert(status == 0); + } + for (i = 1; i <= NTHREADS; i++) { + status = sem_wait(&done); + assert(status == 0); + } + printf("done\n"); + return 0; +} |
