From 13bd3c8253a5c2998ce85a084a854f7a3d0ba7f5 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Tue, 16 Mar 2010 15:14:51 +0100 Subject: Fix player race condition Pressing any key before the player thread set mode to PLAYER_INITIALIZED lead to a song skip and spawning of another player thread. The two player threads were operating on the same variables/memory area, resulting in a crash. Adding a new player state (PLAYER_STARTING) and setting it _before_ invoking pthread_start should resolve this, 'cause the "if PLAYER_FREED-branch" is not taken any more, ergo no second player thread is started. --- src/main.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 82ed674..5428653 100644 --- a/src/main.c +++ b/src/main.c @@ -248,6 +248,9 @@ int main (int argc, char **argv) { BarUiStartEventCmd (&settings, "songstart", curStation, playlist, &player, PIANO_RET_OK); + /* prevent race condition, mode must _not_ be FREED if + * thread has been started */ + player.mode = PLAYER_STARTING; /* start player */ pthread_create (&playerThread, NULL, BarPlayerThread, &player); -- cgit v1.2.3