mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-06-01 09:27:39 +00:00
Remove almost all instances of "volatile" keyword.
As Tiffany pointed out in Bugzilla, volatile is not useful for thread safety: https://software.intel.com/en-us/blogs/2007/11/30/volatile-almost-useless-for-multi-threaded-programming/ Some of these volatiles didn't need to be, some were otherwise protected by spinlocks or mutexes, and some got moved over to SDL_atomic_t data, etc. Fixes Bugzilla #3220.
This commit is contained in:
parent
21f66ea295
commit
fa8c83c1c1
11 changed files with 66 additions and 72 deletions
|
@ -21,7 +21,7 @@
|
|||
|
||||
#define NUMTHREADS 10
|
||||
|
||||
static char volatile time_for_threads_to_die[NUMTHREADS];
|
||||
static SDL_atomic_t time_for_threads_to_die[NUMTHREADS];
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
|
@ -58,7 +58,7 @@ ThreadFunc(void *data)
|
|||
}
|
||||
|
||||
SDL_Log("Thread '%d' waiting for signal\n", tid);
|
||||
while (time_for_threads_to_die[tid] != 1) {
|
||||
while (SDL_AtomicGet(&time_for_threads_to_die[tid]) != 1) {
|
||||
; /* do nothing */
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,7 @@ main(int argc, char *argv[])
|
|||
for (i = 0; i < NUMTHREADS; i++) {
|
||||
char name[64];
|
||||
SDL_snprintf(name, sizeof (name), "Parent%d", i);
|
||||
time_for_threads_to_die[i] = 0;
|
||||
SDL_AtomicSet(&time_for_threads_to_die[i], 0);
|
||||
threads[i] = SDL_CreateThread(ThreadFunc, name, (void*) (uintptr_t) i);
|
||||
|
||||
if (threads[i] == NULL) {
|
||||
|
@ -102,7 +102,7 @@ main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
for (i = 0; i < NUMTHREADS; i++) {
|
||||
time_for_threads_to_die[i] = 1;
|
||||
SDL_AtomicSet(&time_for_threads_to_die[i], 1);
|
||||
}
|
||||
|
||||
for (i = 0; i < NUMTHREADS; i++) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue