[SDL] SDL events and threads on Win32
alex.barry at gmail.com
Thu Feb 9 04:54:07 PST 2006
Why not only use one event handler and poll/wait for events in a main loop?
if you are already passing something to the thread, create a struct/class to
hold what you are sending, and the event jibberish...the events will point
the main loop event variable...
example.whatever = (void *)variable;
&example.events = &mainevents;
SDL_CreateThread( &funcname, &example );
On 2/9/06, skaller <skaller at users.sourceforge.net> wrote:
> I believe I have found the problem I was having with events
> and threads on Win32. The documentation isn't really clear
> what should work and what should not.
> Could someone confirm my analysis, or point out
> any errors?
> At present, SDL creates a single window, in some thread.
> Windows queued messages are queued on a per thread basis.
> SDL uses simplified Win32 calls to process messages,
> these calls process messages for the current thread.
> The native event handling code itself isn't run in
> a separate thread on Win32. Also, user queries
> are not asynchronous -- SDL_WaitEvent etc call
> SDL_PumpEvents which invokes the native code directly.
> Thus, trying to call SDL_WaitEvent in a separate thread
> doesn't work -- it's trying to read events for a thread
> which doesn't own a window and so won't get any windowing
> For my purpose at least this is a serious problem,
> events are asynchronous and must be processed asynchronously
> and without user polling. Whilst I can hack a fix to my
> wrapper code by busy waiting, it may be possible to solve
> this problem properly, in SDL itself.
> As I understand it, the SDL model is ONE window,
> ONE application, multiple threads. Thus from SDL's
> viewpoint SDL threads should all be associated with
> events from that one window -- there's no ambiguity,
> as there would be in general.
> Windows allows reading another threads events,
> so if a record is kept of the thread which creates
> the window, then any thread can read the events.
> Events can also be sent across thread boundaries.
> I have no idea if the API is sustained using DirectX though.
> Is there any interest in fixing SDL events so they work
> in separate threads on Win32? Anyone see any problems
> doing it?
> John Skaller <skaller at users dot sf dot net>
> Felix, successor to C++: http://felix.sf.net
> SDL mailing list
> SDL at libsdl.org
Smith: "...Why, Mr Anderson, Why - Do - You - Persist?"
Neo: "Because I choose to."
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SDL