usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / test-thrd_exit.c
blob622f4d55910a47ce261b3df442e2dec1377a71bb
1 /* Test of thrd_exit () 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. */
19 #include <config.h>
21 #include <threads.h>
23 #include <stdio.h>
24 #include <string.h>
26 #include "macros.h"
28 /* This test is like test-thrd_create.c, except that is uses a thrd_exit()
29 invocation instead of 'return' to provide the thread's result code. */
31 static thrd_t main_thread_before;
32 static thrd_t main_thread_after;
33 static thrd_t worker_thread;
35 #define MAGIC 1266074729
36 static volatile int work_done;
38 static int
39 worker_thread_func (void *arg)
41 work_done = 1;
42 thrd_exit (MAGIC);
43 return 0xBADC0DE;
46 int
47 main ()
49 main_thread_before = thrd_current ();
51 if (thrd_create (&worker_thread, worker_thread_func, NULL) == thrd_success)
53 int ret;
55 /* Check that thrd_current () has the same value before than after the
56 first call to thrd_create (). */
57 main_thread_after = thrd_current ();
58 ASSERT (memcmp (&main_thread_before, &main_thread_after,
59 sizeof (thrd_t))
60 == 0);
62 ASSERT (thrd_join (worker_thread, &ret) == thrd_success);
64 /* Check the return value of the thread. */
65 ASSERT (ret == MAGIC);
67 /* Check that worker_thread_func () has finished executing. */
68 ASSERT (work_done);
70 return test_exit_status;
72 else
74 fputs ("thrd_create failed\n", stderr);
75 return 1;