]> git.pond.sub.org Git - empserver/commit
Fix synchronization between shutdown and player threads
authorMarkus Armbruster <armbru@pond.sub.org>
Tue, 27 Mar 2012 17:58:31 +0000 (19:58 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Thu, 26 Apr 2012 18:05:28 +0000 (20:05 +0200)
commit49ae6a7b9d81d2dfbad8e26ff48d8a3f071f2c66
tree511564319c97b3b0c43ff4c0fd835ffa1cdfe961
parent86f029457300e29749d19a098ab15bdd2c1dfd5d
Fix synchronization between shutdown and player threads

shutdwn() sets the EOF indicator, aborts the running command, if any,
forbids sleeping on I/O and wakes up the player thread, for all player
threads in state PS_PLAYING.  It takes play_lock to prevent new
commands from running.  It then waits up to 3s for player threads to
terminate, by polling player_next(), to let output buffers drain.

Issues:

1. Polling is lame.

2. New player threads can still enter state PS_PLAYING.  They'll block
   as soon as they try to run a command.  Somehwat unclean.

3. We can exit before all player threads left state PS_PLAYING, losing
   a treasury update, play time update, and log entries.  Could happen
   when player threads blocked on output until commit 90b3abc5 fixed
   that; its commit message describes the bug's impact in more detail.
   Since then, the bug shouldn't bite in practice, because player
   threads should leave state PS_PLAYING quickly.

Fix by introducing shutdown_lock: player threads in state PS_PLAYING
hold it shared, shutdwn() takes it exclusive, instead of play_lock.
Takes care of the issues as follows:

3. shutdwn() waits until all player threads left state PS_PLAYING, no
   matter how long it takes them.

2. New player threads block before entering state PS_PLAYING.

1. shutdwn() still polls up to 3s for player threads to terminate.
   Still lame.  Left for another day.
include/server.h
src/lib/player/login.c
src/server/main.c