source: CIVL/examples/translation/pthread/mutexTest.c@ 764d472

1.23 2.0 main test-branch
Last change on this file since 764d472 was a6e9777, checked in by Manchun Zheng <zmanchun@…>, 12 years ago

fixed the problem of having return statements in atom blocks; added two tests for pthread.

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

  • Property mode set to 100644
File size: 600 bytes
Line 
1#include <pthread.h>
2
3#define MAXTHRDS 3
4
5pthread_mutex_t mutexsum;
6int shared;
7
8void *thread(void *arg)
9{
10 int local = (int) (arg);
11
12 pthread_mutex_lock (&mutexsum);
13 shared = local;
14 pthread_mutex_unlock (&mutexsum);
15}
16
17int main (int argc, char *argv[])
18{
19 pthread_attr_t attr;
20 pthread_t thrds[MAXTHRDS];
21 int i;
22
23 pthread_mutex_init(&mutexsum, NULL);
24 pthread_attr_init(&attr);
25 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
26 for(i=0;i<MAXTHRDS;i++)
27 pthread_create(&thrds[i], &attr, thread, (void *)i);
28 for(i=0;i<MAXTHRDS;i++)
29 pthread_join(thrds[i], 0);
30}
Note: See TracBrowser for help on using the repository browser.