1 /* Test of pthread_create () function.
2 Copyright (C) 2011-2024 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2011. */
28 static pthread_t main_thread_before
;
29 static pthread_t main_thread_after
;
30 static pthread_t worker_thread
;
32 #define MAGIC ((void *) 1266074729)
33 static volatile int work_done
;
36 worker_thread_func (_GL_UNUSED
void *arg
)
45 main_thread_before
= pthread_self ();
47 if (pthread_create (&worker_thread
, NULL
, worker_thread_func
, NULL
) == 0)
51 /* Check that pthread_self () has the same value before than after the
52 first call to pthread_create (). */
53 main_thread_after
= pthread_self ();
54 ASSERT (memcmp (&main_thread_before
, &main_thread_after
,
58 ASSERT (pthread_join (worker_thread
, &ret
) == 0);
60 /* Check the return value of the thread. */
61 ASSERT (ret
== MAGIC
);
63 /* Check that worker_thread_func () has finished executing. */
66 return test_exit_status
;
70 fputs ("pthread_create failed\n", stderr
);