annotate tests/test-thread_create.c @ 16465:c0803728f645

New module 'modfl-ieee'. * modules/modfl-ieee: New file.
author Bruno Haible <bruno@clisp.org>
date Sun, 26 Feb 2012 17:55:31 +0100
parents ec738d6aeef5
children e542fd46ad6f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15373
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of gl_thread_create () macro.
16201
8250f2777afc maint: update all copyright year number ranges
Jim Meyering <meyering@redhat.com>
parents: 15373
diff changeset
2 Copyright (C) 2011-2012 Free Software Foundation, Inc.
15373
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2011. */
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <config.h>
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include "glthread/thread.h"
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include <stdio.h>
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include <string.h>
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #include "macros.h"
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 static gl_thread_t main_thread_before;
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 static gl_thread_t main_thread_after;
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 static gl_thread_t worker_thread;
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 static int dummy;
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 static volatile int work_done;
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 static void *
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 worker_thread_func (void *arg)
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 {
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 work_done = 1;
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 return &dummy;
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 }
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 int
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 main ()
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 {
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 main_thread_before = gl_thread_self ();
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 if (glthread_create (&worker_thread, worker_thread_func, NULL) == 0)
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 {
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 void *ret;
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 /* Check that gl_thread_self () has the same value before than after the
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 first call to gl_thread_create (). */
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 main_thread_after = gl_thread_self ();
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 ASSERT (memcmp (&main_thread_before, &main_thread_after,
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 sizeof (gl_thread_t))
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 == 0);
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 gl_thread_join (worker_thread, &ret);
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 /* Check the return value of the thread. */
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 ASSERT (ret == &dummy);
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 /* Check that worker_thread_func () has finished executing. */
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 ASSERT (work_done);
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 return 0;
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 }
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 else
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 {
16214
ec738d6aeef5 Talk about "native Windows API", not "Win32".
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
70 #if USE_POSIX_THREADS || USE_SOLARIS_THREADS || USE_PTH_THREADS || USE_WINDOWS_THREADS
15373
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 fputs ("glthread_create failed\n", stderr);
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 return 1;
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 #else
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 fputs ("Skipping test: multithreading not enabled\n", stderr);
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 return 77;
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 #endif
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 }
335a77ae4731 Tests for module 'thread'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 }