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