1. pygame
  2. pygame
  3. pygame
  4. Pull requests

Pull requests

#32 Merged
Repository
metagriffin
Branch
fastevent-proper-condlock
Repository
pygame
Branch
default

surround all condition signaling with mutex lock protection

Author
  1. metagriffin
Reviewers
Description

in threaded programming, condition signaling must only be done from within a context that has a lock on the associated mutex (see http://wiki.libsdl.org/SDL_CondWait for an example). this PR fixes fastevents.c to obey that rule.

Comments (5)

  1. René Dudfield

    There's also the python stuff which interacts with it. eg. from fastevent.c (it uses fastevents.c) which interacts with the python GIL unlocking/locking primitives.

        Py_BEGIN_ALLOW_THREADS;      <------ saves thread state, has to have python GIL.
        status = FE_WaitEvent (&event);
        Py_END_ALLOW_THREADS;  <--- restores thread state
    

    https://docs.python.org/3/c-api/init.html#c.PyEval_SaveThread

    In practice there is already some sort of locking going on in those python macros where the race would never possibly happen when called by python code. Also there is the overhead of calling the python functions which just by itself makes this VERY unlikely too. Of course I can't prove that. I only know there have been no reported failures (doesn't mean they don't happen). Just looking at the SDL code without considering the python parts wrapping it is not the full story.

    Races like this are also a very hard thing to test (especially on so many platforms), and I'd rather not mess with this unless it's proven broken.