Threadsafety

Hi again =) … This time i’m wondering about thread safety, or, how
to properly make my event filterer thread safe ? I’ve got a event
filtering function, FilterEvents, that use two variables, SIF_AreaC
and SIF_Areas, that might also be modified outside of the event
thread (fx. by manual user calls).

Right now i’m just using a simple mutex that is locked before access
to these, and unlocked when done, both inside the event filterer and
in the external modifying functions. Is this The Right Way to do it ?

I took a peek into the SDL source (SDL_events.c), and saw there that
SDL also wait for a “safe” variable, check what the current thread
is, and such. Is all this necessarry for this simple case ?

Thanks for any help =)–
Trick


Linux User #229006 * http://counter.li.org

Hi again =) … This time i’m wondering about thread safety, or, how
to properly make my event filterer thread safe ? I’ve got a event
filtering function, FilterEvents, that use two variables, SIF_AreaC
and SIF_Areas, that might also be modified outside of the event
thread (fx. by manual user calls).

Right now i’m just using a simple mutex that is locked before access
to these, and unlocked when done, both inside the event filterer and
in the external modifying functions. Is this The Right Way to do it ?
yes…

I took a peek into the SDL source (SDL_events.c), and saw there that
SDL also wait for a “safe” variable, check what the current thread
is, and such. Is all this necessarry for this simple case ?

mmhh… i don’t know how simple your program is !

roughly, just global variable need to be enclosed in mutex, variables on
stack (ie: argument of function call) are no problem, except if they are
pointer on memory used by someone else…
and (not exactly, but mostly true) only write access should be enclose
by mutex, read access have no such problem. (though not really exact as
you shouldn’t read an array while swapping element)

i want to add, if you have one thread updating variables and other just
reading you need no mutex at all…
though you might need synchronization…