1.23
2.0
main
test-branch
| Rev | Line | |
|---|
| [a6e9777] | 1 | #include <pthread.h>
|
|---|
| 2 |
|
|---|
| 3 | #define MAXTHRDS 3
|
|---|
| 4 |
|
|---|
| 5 | pthread_mutex_t mutexsum;
|
|---|
| 6 | int shared;
|
|---|
| 7 |
|
|---|
| 8 | void *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 |
|
|---|
| 17 | int 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.