On 03/06/2026 3:54 pm, Leo Yan wrote:
On Tue, Jun 02, 2026 at 03:26:51PM +0100, James Clark wrote:
+#define DEFINE_THREAD(n) \ +noinline void *named_threads_thread##n(void *arg __maybe_unused) \ +{ \
- pthread_setname_np(pthread_self(), "thread" #n); \
- for (int i = 0; i < iterations; i++) \
named_threads_work *= 3; \\- return NULL; \
+}
+static int named_threads(int argc, const char **argv) +{
- pthread_t threads[MAX_THREADS];
- int nr_threads = 1;
- int err = 0;
- if (argc > 0)
nr_threads = atoi(argv[0]);- if (nr_threads <= 0 || nr_threads > MAX_THREADS) {
fprintf(stderr, "Error: num threads must be 1 - %d\n", MAX_THREADS);return 1;- }
- if (argc > 1)
iterations = atoi(argv[1]);- if (iterations < 0) {
fprintf(stderr, "Error: iterations must be non-negative\n");return 1;- }
- for (int i = 0; i < nr_threads; i++) {
int ret;ret = pthread_create(&threads[i], NULL, thread_fns[i], NULL);Just curious this can be simplified to a thread function, like:
noinline void *named_thread(void *arg) { char name[16];
snprintf(name, sizeof(name), "thread%d", int(arg)); pthread_setname_np(pthread_self(), name); ... return NULL;}
Thanks, Leo
Only if you don't want to check for symbols as well. I thought if we were going to spawn a load of threads and look for thread names we might as well check that the symbols match at the same time.
If all of the threads run the same function you can't do that.