source:
src/benchmark/create_pthrd.c@
6840e7c
| Last change on this file since 6840e7c was eb2fe4f, checked in by , 9 years ago | |
|---|---|
|
|
| File size: 550 bytes | |
| Rev | Line | |
|---|---|---|
| [5013c62] | 1 | #include <pthread.h> |
| 2 | #include <err.h> | |
| 3 | #include <stdlib.h> | |
| 4 | #include <stdio.h> | |
| 5 | ||
| 6 | static void *foo(void *arg) { | |
| 7 | return arg; | |
| 8 | } | |
| 9 | ||
| 10 | int main(int argc, char* argv[]) { | |
| 11 | size_t n = 1000000; | |
| 12 | if( argc > 2 ) return 1; | |
| 13 | if( argc == 2 ) { | |
| 14 | n = atoi(argv[1]); | |
| 15 | } | |
| [eb2fe4f] | 16 | printf("create %lu pthreads ... ", n); |
| [5013c62] | 17 | |
| 18 | for (size_t i = 0; i < n; i++) { | |
| [d6ff3ff] | 19 | pthread_t thread; |
| 20 | if (pthread_create(&thread, NULL, foo, NULL) < 0) { | |
| [eb2fe4f] | 21 | perror( "failure" ); |
| [5013c62] | 22 | return 1; |
| 23 | } | |
| [d6ff3ff] | 24 | |
| 25 | if (pthread_join( thread, NULL) < 0) { | |
| [eb2fe4f] | 26 | perror( "failure" ); |
| [5013c62] | 27 | return 1; |
| 28 | } | |
| 29 | } | |
| [eb2fe4f] | 30 | printf("finish\n"); |
| [5013c62] | 31 | } |
Note:
See TracBrowser
for help on using the repository browser.