4 * Unlike testthread which is mainly concerned about testing thread
5 * semantics this test is used to exercise the thread creation and
6 * accounting. A version of this test found a problem with clashing
7 * cpu_indexes which caused a break in plugin handling.
9 * Based on the original test case by Nikolay Igotti.
11 * Copyright (c) 2020 Linaro Ltd
13 * SPDX-License-Identifier: GPL-2.0-or-later
28 static void *thread_fn(void* varg
)
30 ThreadArg
*arg
= varg
;
36 int main(int argc
, char **argv
)
42 max_threads
= atoi(argv
[1]);
44 threads
= calloc(sizeof(pthread_t
), max_threads
);
46 for (i
= 0; i
< max_threads
; i
++) {
47 ThreadArg
*arg
= calloc(sizeof(ThreadArg
), 1);
49 pthread_create(threads
+ i
, NULL
, thread_fn
, arg
);
52 printf("Created %d threads\n", max_threads
);
54 /* sleep until roughly half the threads have "finished" */
55 usleep(max_threads
* 50);
57 for (i
= 0; i
< max_threads
; i
++) {
58 pthread_join(threads
[i
], NULL
);