SFML community forums

Help => Window => Topic started by: user31182 on July 22, 2013, 06:21:14 pm

Title: How thread safe is a sfml window?
Post by: user31182 on July 22, 2013, 06:21:14 pm
I notice there is a section in the tutorials about threads and sfml.

The example is how to use a thread to render on a sfml window.

I presume that this is thread safe?

How safe would be event handling in the same loop?  I assume this must be safe, because events must be handled somewhere, whether this be in the main loop or the rendering loop.

This is a question about sfml generally, although I am mostly interested in OpenGL rendering and event processing. How thread safe are these things?

What sort of things are and are not thread safe. If something isn't thread safe, what is likely to be the best way of making it so? (Mutex, atomic operations, etc)
Title: Re: How thread safe is a sfml window?
Post by: Laurent on July 22, 2013, 07:52:24 pm
SFML is generally not thread-safe itself, but OS and third-party functions may be thread-safe.

Regarding your specific question, since input/events and rendering don't share anything, you can have both running in two different threads without any problem.
Title: Re: How thread safe is a sfml window?
Post by: user31182 on July 24, 2013, 04:13:58 am
Okay thanks once again Laurent for your speedy replies!
Title: Re: How thread safe is a sfml window?
Post by: Ancurio on July 25, 2013, 08:02:45 pm
I think I recall having read somewhere that input event handling doesn't work anywhere besides the main thread on at least OSX (confirm Laurent?), so you'd probably be best off doing the rendering in a dedicated thread.
Title: Re: How thread safe is a sfml window?
Post by: Laurent on July 25, 2013, 08:09:49 pm
Yep. All the OS limitations are described in the tutorial.