10 #define NUM_THREADS 10
12 #define NUM_SOS_PER_THREAD (NUM_SOS/NUM_THREADS)
14 typedef void (*voidfn
)(void);
19 __vtv_verify_fail (void **data_set_ptr
, const void *vtbl_pointer
)
26 void do_dlopen(int so_num
)
28 char so_name
[sizeof("soxxx.so")];
29 sprintf(so_name
, "so%d.so", so_num
);
30 // printf("dl-opening %s\n", so_name);
31 void * dlhandle
= dlopen(so_name
, RTLD_NOW
);
34 fprintf(stderr
, "dlopen so:%s error: %s\n", so_name
, dlerror());
37 char so_entry
[sizeof("so_entry_xxx")];
38 sprintf(so_entry
, "so_entry_%d", so_num
);
39 voidfn so_entry_fn
= (voidfn
)dlsym(dlhandle
, so_entry
);
42 fprintf(stderr
, "so:%s dlsym error: %s\n", so_name
, dlerror());
51 volatile int threads_completed_it
= 0;
52 volatile int current_wave
= -1;
54 void * do_dlopens(void * ptid
)
56 for (int k
= 0; k
< NUM_REPEATS
; k
++)
59 for (int i
= 0; i
< NUM_SOS_PER_THREAD
; i
++)
61 while (current_wave
< (k
*NUM_SOS_PER_THREAD
+ i
)) /* from 0 to 99 */
64 do_dlopen((NUM_SOS_PER_THREAD
* *(int *)ptid
) + i
);
68 old_value
= threads_completed_it
;
69 } while (!__sync_bool_compare_and_swap(&threads_completed_it
, old_value
, old_value
+ 1));
71 if (old_value
== (NUM_THREADS
- 1)) // Only one thread will do this.
73 threads_completed_it
= 0;
74 printf("%c%d", 13, current_wave
+ 1);
87 pthread_t thread_ids
[NUM_THREADS
];
88 int thread_nids
[NUM_THREADS
];
90 for (int t
= 0; t
< NUM_THREADS
; t
++ )
93 if (pthread_create(&thread_ids
[t
], NULL
, do_dlopens
, &thread_nids
[t
]) != 0)
95 printf("failed pthread_create\n");
100 current_wave
= 0; // start the work on the other threads
102 for (int t
= 0; t
< NUM_THREADS
; t
++)
103 if (pthread_join(thread_ids
[t
], NULL
) != 0)
105 printf("failed pthread_join\n");