Changes in / [dcbb03b:446ffa3]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/busy.c
rdcbb03b r446ffa3 1 1 #include <stdbool.h> 2 #include <stdio.h>3 2 #include <stdlib.h> 4 3 #include <pthread.h> … … 32 31 } 33 32 34 int main(int argc, const char * const argv[]) { 35 char * endptr; 36 int nThreads = 15; 37 switch(argc) { 38 case 1: 39 break; 40 case 2: 41 nThreads = strtol(argv[1], &endptr, 10); 42 if( *endptr != 0 || nThreads <= 0 ) { 43 fprintf(stderr, "Invalid number of threads %s\n", argv[1]); 44 return 1; 45 } 46 break; 47 default: 48 fprintf(stderr, "Usage: %s [no of threads]\n", argv[0]); 49 return 1; 50 } 51 printf("Running %d threads\n", nThreads); 52 while(true) { 53 pthread_t t[nThreads]; 54 for(int i = 0; i < nThreads; i++) { 55 pthread_create( &t[i], NULL, CallingMalloc, NULL ); 56 } 33 int main() { 34 while(true) { 35 pthread_t t[15]; 36 for(int i = 0; i < 15; i++) { 37 pthread_create( &t[i], NULL, CallingMalloc, NULL ); 38 } 57 39 58 for(int i = 0; i < nThreads; i++) { 59 pthread_join( t[i], NULL ); 60 } 61 } 62 return 0; 40 for(int i = 0; i < 15; i++) { 41 pthread_join( t[i], NULL ); 42 } 43 } 63 44 }
Note: See TracChangeset
for help on using the changeset viewer.