1 /* Measure pthread_create thread creation with different stack
4 Copyright (C) 2017-2024 Free Software Foundation, Inc.
5 This file is part of the GNU C Library.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, see
19 <https://www.gnu.org/licenses/>. */
23 #include <support/xthread.h>
28 thread_create_init (void)
30 pgsize = sysconf (_SC_PAGESIZE);
34 thread_dummy (void *arg)
40 thread_create (int nthreads, size_t stacksize, size_t guardsize)
43 xpthread_attr_init (&attr);
45 stacksize = stacksize * pgsize;
46 guardsize = guardsize * pgsize;
48 xpthread_attr_setstacksize (&attr, stacksize);
49 xpthread_attr_setguardsize (&attr, guardsize);
51 pthread_t ts[nthreads];
53 for (int i = 0; i < nthreads; i++)
54 ts[i] = xpthread_create (&attr, thread_dummy, NULL);
56 for (int i = 0; i < nthreads; i++)
57 xpthread_join (ts[i]);