1.23
2.0
main
test-branch
| Line | |
|---|
| 1 | #include <pthread.h>
|
|---|
| 2 |
|
|---|
| 3 | int i=1, j=1;
|
|---|
| 4 |
|
|---|
| 5 | #define NUM 6
|
|---|
| 6 |
|
|---|
| 7 | void *
|
|---|
| 8 | t1(void* arg)
|
|---|
| 9 | {
|
|---|
| 10 | int k = 0;
|
|---|
| 11 |
|
|---|
| 12 | for (k = 0; k < NUM; k++)
|
|---|
| 13 | i+=j;
|
|---|
| 14 |
|
|---|
| 15 | pthread_exit(NULL);
|
|---|
| 16 | }
|
|---|
| 17 |
|
|---|
| 18 | void *
|
|---|
| 19 | t2(void* arg)
|
|---|
| 20 | {
|
|---|
| 21 | int k = 0;
|
|---|
| 22 |
|
|---|
| 23 | for (k = 0; k < NUM; k++)
|
|---|
| 24 | j+=i;
|
|---|
| 25 |
|
|---|
| 26 | pthread_exit(NULL);
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | int
|
|---|
| 30 | main(int argc, char **argv)
|
|---|
| 31 | {
|
|---|
| 32 | pthread_t id1, id2;
|
|---|
| 33 |
|
|---|
| 34 | pthread_create(&id1, NULL, t1, NULL);
|
|---|
| 35 | pthread_create(&id2, NULL, t2, NULL);
|
|---|
| 36 |
|
|---|
| 37 | pthread_join(id1, 0);
|
|---|
| 38 | pthread_join(id2, 0);
|
|---|
| 39 |
|
|---|
| 40 | if (i > 377 || j > 377) {
|
|---|
| 41 | ERROR:
|
|---|
| 42 | goto ERROR;
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | return 0;
|
|---|
| 46 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.