Changeset b002261
- Timestamp:
- Mar 1, 2018, 9:28:48 AM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- dcbb03b
- Parents:
- 807d8c3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/busy.c
r807d8c3 rb002261 1 1 #include <stdbool.h> 2 #include <stdio.h> 2 3 #include <stdlib.h> 3 4 #include <pthread.h> … … 31 32 } 32 33 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 } 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 } 39 57 40 for(int i = 0; i < 15; i++) { 41 pthread_join( t[i], NULL ); 42 } 43 } 58 for(int i = 0; i < nThreads; i++) { 59 pthread_join( t[i], NULL ); 60 } 61 } 62 return 0; 44 63 }
Note: See TracChangeset
for help on using the changeset viewer.