1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2018-2021 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 /* Crude spin lock. Threads all spin until this is set to 0. */
27 /* Thread function, just spin until GO is set to 0. */
29 perform_work (void *argument
)
31 /* Cast to volatile to ensure that ARGUMENT is loaded each time around
33 while (*((volatile int*) argument
))
40 /* The spin loop for the main thread. */
44 (void) perform_work (&go
);
45 printf ("Finished from function\n");
48 /* Main program, create some threads which all spin waiting for GO to be
53 pthread_t threads
[NUM_THREADS
];
57 /* Create some threads. */
58 for (index
= 0; index
< NUM_THREADS
; ++index
)
60 printf ("In main: creating thread %d\n", index
);
61 result_code
= pthread_create (&threads
[index
], NULL
, perform_work
, &go
);
62 assert (!result_code
);
67 /* Wait for each thread to complete. */
68 for (index
= 0; index
< NUM_THREADS
; ++index
)
70 /* Block until thread INDEX completes. */
71 result_code
= pthread_join (threads
[index
], NULL
);
72 assert (!result_code
);
73 printf ("In main: thread %d has completed\n", index
);
75 printf ("In main: All threads completed successfully\n");
This page took 0.043624 seconds and 4 git commands to generate.