Threading issue

Hello, I’m using the latest version of SDL 2.0 (1.3?).
Is there a way to create the window in one thread and poll its events in another?
Thank you,
Felipe.

No.

Also while nice, it’s unlikely SDL will ever allow it. As far as I
know, it’s a limitation of the underlying operating system APIs (at
least in the case of some platforms), so there’s nothing SDL can do
about it (short of some crazy threading abuse).

2013/2/16, Felipe - :>

Hello, I’m using the latest version of SDL 2.0 (1.3?).
Is there a way to create the window in one thread and poll its events in
another?
Thank you,
Felipe.

You could build a workaround using domain sockets and pass the polled
SDL event to the subprocess … something like that .
Not the best solution but it might suite.On Sun, 2013-02-17 at 00:09 -0300, Sik the hedgehog wrote:

No.

Also while nice, it’s unlikely SDL will ever allow it. As far as I
know, it’s a limitation of the underlying operating system APIs (at
least in the case of some platforms), so there’s nothing SDL can do
about it (short of some crazy threading abuse).

2013/2/16, Felipe - :

Hello, I’m using the latest version of SDL 2.0 (1.3?).
Is there a way to create the window in one thread and poll its events in
another?
Thank you,
Felipe.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Another workaround would be to spawn another thread exclusively for
the window and then have everything ask that thread to deal with the
window. It isn’t hard to see how troublesome this can be, especially
if there aren’t enough cores to ensure it’s always running (in which
case you could end up with a huge performance penalty - probably not
anywhere as bad as the sockets thing, though…).

2013/2/17, schnitzelhuber :> You could build a workaround using domain sockets and pass the polled

SDL event to the subprocess … something like that .
Not the best solution but it might suite.

On Sun, 2013-02-17 at 00:09 -0300, Sik the hedgehog wrote:

No.

Also while nice, it’s unlikely SDL will ever allow it. As far as I
know, it’s a limitation of the underlying operating system APIs (at
least in the case of some platforms), so there’s nothing SDL can do
about it (short of some crazy threading abuse).

2013/2/16, Felipe - :

Hello, I’m using the latest version of SDL 2.0 (1.3?).
Is there a way to create the window in one thread and poll its events
in
another?
Thank you,
Felipe.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I tried multithreading, and this is what screwed me; so I said screw it.
You could, however, make a wrapper layer which will poll for the events in
the main thread, but process the event on a different thread.On Sun, Feb 17, 2013 at 1:16 PM, Sik the hedgehog < sik.the.hedgehog at gmail.com> wrote:

Another workaround would be to spawn another thread exclusively for
the window and then have everything ask that thread to deal with the
window. It isn’t hard to see how troublesome this can be, especially
if there aren’t enough cores to ensure it’s always running (in which
case you could end up with a huge performance penalty - probably not
anywhere as bad as the sockets thing, though…).

2013/2/17, schnitzelhuber :

You could build a workaround using domain sockets and pass the polled
SDL event to the subprocess … something like that .
Not the best solution but it might suite.

On Sun, 2013-02-17 at 00:09 -0300, Sik the hedgehog wrote:

No.

Also while nice, it’s unlikely SDL will ever allow it. As far as I
know, it’s a limitation of the underlying operating system APIs (at
least in the case of some platforms), so there’s nothing SDL can do
about it (short of some crazy threading abuse).

2013/2/16, Felipe - :

Hello, I’m using the latest version of SDL 2.0 (1.3?).
Is there a way to create the window in one thread and poll its events
in
another?
Thank you,
Felipe.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Why do you need to do that? Some context would help us.On Sat, Feb 16, 2013 at 11:46 PM, Felipe - wrote:

Hello, I’m using the latest version of SDL 2.0 (1.3?).
Is there a way to create the window in one thread and poll its events in
another?


Alejandro Santos

I am not the original poster, but I also usually like to decouple the window and input as well, as I really want as few things holding up the main rendering thread as possible including handling and dispatching input events. I try to handle input in an update thread, which is different from the main (rendering) thread.

I often do this, by creating a thread safe data structure, that holds all events. Events are pushed to this data structure from the main thread, and handled and polled on other threads.On Sunday, February 17, 2013 at 3:57 PM, Alejandro Santos wrote:

On Sat, Feb 16, 2013 at 11:46 PM, Felipe - <katanaofdevastation at hotmail.com (mailto:katanaofdevastation at hotmail.com)> wrote:

Hello, I’m using the latest version of SDL 2.0 (1.3?).
Is there a way to create the window in one thread and poll its events in
another?

Why do you need to do that? Some context would help us.


Alejandro Santos


SDL mailing list
SDL at lists.libsdl.org (mailto:SDL at lists.libsdl.org)
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

SDL’s event structure is thread-safe, so in theory you could pump events on
the main thread and let another thread pull them off and process them.

e.g. (greatly simplified)

Main thread:
while (true) {
SDL_PumpEvents();
Render();
WaitABit();
}

Event thread:
while (true) {
SDL_PeepEvents();
HandleEvent()
}
}On Sun, Feb 17, 2013 at 10:39 AM, Gorm Lai wrote:

I am not the original poster, but I also usually like to decouple the
window and input as well, as I really want as few things holding up the
main rendering thread as possible including handling and dispatching input
events. I try to handle input in an update thread, which is different from
the main (rendering) thread.

I often do this, by creating a thread safe data structure, that holds all
events. Events are pushed to this data structure from the main thread, and
handled and polled on other threads.

On Sunday, February 17, 2013 at 3:57 PM, Alejandro Santos wrote:

On Sat, Feb 16, 2013 at 11:46 PM, Felipe - wrote:

Hello, I’m using the latest version of SDL 2.0 (1.3?).
Is there a way to create the window in one thread and poll its events in
another?

Why do you need to do that? Some context would help us.


Alejandro Santos


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org