source: CIVL/examples/pthread/errorTest/barrierExample.c@ bd7a43e

main test-branch
Last change on this file since bd7a43e was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 606 bytes
Line 
1#include <pthread.h>
2pthread_barrier_t barr;
3
4void * thread_worker(void *arg) {
5 // do work
6 // now make all the threads sync up
7 int id = (int)arg;
8 int res = pthread_barrier_wait(&barr);
9 pthread_exit(NULL);
10}
11
12
13int main(void) {
14 int nthreads = 5;
15 pthread_t threads[nthreads];
16 pthread_barrier_init(&barr, NULL, nthreads);
17 for(int i=0; i<nthreads; i++) {
18 pthread_create(&threads[i], NULL, thread_worker, (void *) i);
19 }
20 for(int i=0; i<nthreads; i++) {
21 pthread_join(threads[i], NULL);
22 }
23 pthread_barrier_destroy(&barr);
24 pthread_exit(NULL);
25}
Note: See TracBrowser for help on using the repository browser.