source: CIVL/examples/pthread/svcomp/threadLocal.c@ 4a0cb10

1.23 2.0 main test-branch
Last change on this file since 4a0cb10 was 514de69, checked in by Manchun Zheng <zmanchun@…>, 11 years ago

added example for thread local variables

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

  • Property mode set to 100644
File size: 417 bytes
RevLine 
[514de69]1#include<pthread.h>
2#include<assert.h>
3
4int f(int x){
5
6 assert(!x);
7 return x!=0;
8}
9
10__thread int id=-1;
11
12int isRoot(){
13 assert(id >= 0);
14 return id == 0;
15}
16
17void* thread(void *arg){
18 id=(int)arg;
19 isRoot();
20}
21
22int main(){
23 pthread_t t0,t1;
24
25 pthread_create(&t0, 0, thread, (void*)0);
26 pthread_create(&t1, 0, thread, (void*)1);
27 pthread_join(t0, 0);
28 pthread_join(t1, 0);
29 assert(id==-1);
30 return 0;
31}
32
33
Note: See TracBrowser for help on using the repository browser.