Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: How thread safe is a sfml window?  (Read 2428 times)

0 Members and 1 Guest are viewing this topic.

user31182

  • Newbie
  • *
  • Posts: 23
    • View Profile
    • Email
How thread safe is a sfml window?
« 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)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: How thread safe is a sfml window?
« Reply #1 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.
Laurent Gomila - SFML developer

user31182

  • Newbie
  • *
  • Posts: 23
    • View Profile
    • Email
Re: How thread safe is a sfml window?
« Reply #2 on: July 24, 2013, 04:13:58 am »
Okay thanks once again Laurent for your speedy replies!

Ancurio

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Re: How thread safe is a sfml window?
« Reply #3 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: How thread safe is a sfml window?
« Reply #4 on: July 25, 2013, 08:09:49 pm »
Yep. All the OS limitations are described in the tutorial.
Laurent Gomila - SFML developer

 

anything