pthread_self: allow multiple waves

Original motivation: determine if gem5's join releases CPU cores.
It does.
This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-11-04 00:00:00 +00:00
parent a06672a20d
commit 425d3a5713

View File

@@ -57,7 +57,7 @@ void* main_thread(void *arg) {
int main(int argc, char**argv) { int main(int argc, char**argv) {
pthread_t *threads; pthread_t *threads;
unsigned int nthreads, i, *thread_args; unsigned int nthreads, nwaves, i, *thread_args, wave;
int rc; int rc;
/* CLI arguments. */ /* CLI arguments. */
@@ -66,9 +66,15 @@ int main(int argc, char**argv) {
} else { } else {
nthreads = 1; nthreads = 1;
} }
if (argc > 2) {
nwaves = strtoll(argv[2], NULL, 0);
} else {
nwaves = 1;
}
threads = malloc(nthreads * sizeof(*threads)); threads = malloc(nthreads * sizeof(*threads));
thread_args = malloc(nthreads * sizeof(*thread_args)); thread_args = malloc(nthreads * sizeof(*thread_args));
for (wave = 0; wave < nwaves; wave++) {
/* main thread for comparison. */ /* main thread for comparison. */
printf( printf(
"tid, getpid(), pthread_self() = " "tid, getpid(), pthread_self() = "
@@ -103,6 +109,7 @@ int main(int argc, char**argv) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
}
/* Cleanup. */ /* Cleanup. */
free(thread_args); free(thread_args);