main
test-branch
| Line | |
|---|
| 1 | #include<pthread.h>
|
|---|
| 2 | #include<assert.h>
|
|---|
| 3 |
|
|---|
| 4 | int f(int x){
|
|---|
| 5 |
|
|---|
| 6 | assert(!x);
|
|---|
| 7 | return x!=0;
|
|---|
| 8 | }
|
|---|
| 9 |
|
|---|
| 10 | __thread int id=-1;
|
|---|
| 11 |
|
|---|
| 12 | int isRootWork(){
|
|---|
| 13 | assert(id >= 0);
|
|---|
| 14 | return id == 0;
|
|---|
| 15 | }
|
|---|
| 16 |
|
|---|
| 17 | int isRoot(){
|
|---|
| 18 | isRootWork();
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | void* thread(void *arg){
|
|---|
| 22 | id=(int)arg;
|
|---|
| 23 | isRoot();
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | int main(){
|
|---|
| 27 | pthread_t t0,t1;
|
|---|
| 28 |
|
|---|
| 29 | pthread_create(&t0, 0, thread, (void*)0);
|
|---|
| 30 | pthread_create(&t1, 0, thread, (void*)1);
|
|---|
| 31 | pthread_join(t0, 0);
|
|---|
| 32 | pthread_join(t1, 0);
|
|---|
| 33 | assert(id==-1);
|
|---|
| 34 | return 0;
|
|---|
| 35 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.