source: src/benchmark/create_pthrd.c@ b1e63ac5

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since b1e63ac5 was 5013c62, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

added several benchmarks to measure creation, some work needs to be done on them

  • Property mode set to 100644
File size: 604 bytes
Line 
1#include <pthread.h>
2#include <err.h>
3#include <stdlib.h>
4#include <stdio.h>
5
6static void *foo(void *arg) {
7 return arg;
8}
9
10int 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 }
16 printf("%lu\n", n);
17
18 for (size_t i = 0; i < n; i++) {
19 pthread_attr_t attr;
20 if (pthread_attr_init(&attr) < 0) {
21 return 1;
22 }
23 if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) < 0) {
24 return 1;
25 }
26 pthread_t thread;
27 if (pthread_create(&thread, &attr, foo, NULL) < 0) {
28 return 1;
29 }
30 }
31 pthread_exit(NULL);
32 return 0;
33}
Note: See TracBrowser for help on using the repository browser.