benchtests: Fix validate_benchout.py exceptions
[platform/upstream/glibc.git] / benchtests / thread_create-source.c
1 /* Measure pthread_create thread creation with different stack
2    and guard sizes.
3
4    Copyright (C) 2017-2021 Free Software Foundation, Inc.
5    This file is part of the GNU C Library.
6
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.
11
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.
16
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/>.  */
20
21 #include <stdio.h>
22 #include <unistd.h>
23 #include <support/xthread.h>
24
25 static size_t pgsize;
26
27 static void
28 thread_create_init (void)
29 {
30   pgsize = sysconf (_SC_PAGESIZE);
31 }
32
33 static void *
34 thread_dummy (void *arg)
35 {
36   return NULL;
37 }
38
39 static void
40 thread_create (int nthreads, size_t stacksize, size_t guardsize)
41 {
42   pthread_attr_t attr;
43   xpthread_attr_init (&attr);
44
45   stacksize = stacksize * pgsize;
46   guardsize = guardsize * pgsize;
47
48   xpthread_attr_setstacksize (&attr, stacksize);
49   xpthread_attr_setguardsize (&attr, guardsize);
50
51   pthread_t ts[nthreads];
52
53   for (int i = 0; i < nthreads; i++)
54     ts[i] = xpthread_create (&attr, thread_dummy, NULL);
55
56   for (int i = 0; i < nthreads; i++)
57     xpthread_join (ts[i]);
58 }