From 03851e8991184a2c44f561a202f1da6084c19d0d Mon Sep 17 00:00:00 2001
From: Adrien
- Comme vous pouvez le voir, vous n'avez même pas besoin d'activer la fenêtre dans le thread de dessin, SFML le fait automatiquement pour vous dès que nécessaire.
+ Remarque : vous n'avez pas besoin d'activer la fenêtre dans le thread de dessin, SFML le fait automatiquement pour vous dès que nécessaire à condition
+ que le contexte OpenGL ait été correctement désactivé auparavant.
Souvenez-vous : il faut toujours créer la fenêtre et gérer ses évènements dans le thread principal, pour un maximum de portabilité, comme expliqué dans le
tutoriel sur les fenêtres.
+ Bien que permette de dessiner dans un thread et de gérer ses évènements dans un autre, ses autres fonctions ne sont pas
+ pour autant thread-safe.
+ En particulier, vous devez arrêter le thread de dessin avant d'appeler la fonction
- As you can see, you don't even need to bother with the activation of the window in the rendering thread, SFML does it automatically for you whenever it needs to be done.
+ Note : you don't need to activate the window in the rendering thread, SFML does it automatically for you whenever it needs
+ to be done, as long as the OpenGL context is properly deactivate beforehand.
Remember to always create the window and handle its events in the main thread for maximum portability. This is explained in the
window tutorial.
+ Even if allows you to draw in a thread and handle its events in another, it's other functions are not thread-safe.
+ In particular, you must stop the rendering thread before calling the function close
.
+close
.
+
- Bien que permette de dessiner dans un thread et de gérer ses évènements dans un autre, ses autres fonctions ne sont pas
- pour autant thread-safe.
- En particulier, vous devez arrêter le thread de dessin avant d'appeler la fonction close
.
+ Vous pouvez dessiner et gérer les évènements d'une fenêtre dans deux threads différents car ces deux fonctionnalités sont complètement indépendantes.
+ La classe n'est autrement pas thread-safe.
+ En particulier, vous devez vous assurer que la fenêtre ne soit plus utilisée que dans un seul thread avant de la fermer.
- Even if allows you to draw in a thread and handle its events in another, it's other functions are not thread-safe.
- In particular, you must stop the rendering thread before calling the function close
.
+ You can draw and handle the events of a window in two different threads because these two functionalities dont share anything.
+ The class is otherwise not thread-safe.
+ In particular, you must ensure the window is only used in one thread before closing it.
+ Les instances des classes fournies par SFML ne sont en général pas thread-safe. Vous devez les protéger si vous les utilisez + dans plusieurs threads en même temps ! +
Il existe plusieurs outils de programmation pour vous aider à protéger les variables partagées et rendre votre code thread-safe, ils sont appelés "primitives de synchronisation". Les plus communs sont les mutexs, les sémaphores, les conditions d'attente et les spin locks. diff --git a/tutorials/2.6/system-thread.php b/tutorials/2.6/system-thread.php index 193b1aa4d..f0377b47a 100644 --- a/tutorials/2.6/system-thread.php +++ b/tutorials/2.6/system-thread.php @@ -222,6 +222,9 @@ classes are a good solution. since threads run in parallel, it means that a variable or function might be used concurrently from several threads at the same time. If the operation is not thread-safe, it can lead to undefined behavior (ie. it might crash or corrupt data).
++ Instances of classes defined by SFML are usually not thread-safe. You must protect them if you use them in multiple threads at the same time ! +
Several programming tools exist to help you protect shared data and make your code thread-safe, these are called synchronization primitives. Common ones
are mutexes, semaphores, condition variables and spin locks. They are all variants of the same concept: they protect a piece of code by allowing only
From a31a1498c978afd631765b5e8e8553f3dbe6d4bf Mon Sep 17 00:00:00 2001
From: Adrien One thing to remember is that although the operating system marks your thread as "awake" after it is done sleeping, even for exactly the correct duration, it doesn't mean it resumes execution immediately. It could have just missed the moment at which the scheduler selects which task to execute next and thus must wait for the next transition. In this case, although your thread slept for the correct amount, it will appear to you as if it slept for more. SFML doesn't allow you to sleep for 0 duration, however if you could, you would notice that it in fact takes a slight bit of time as well. This is because it is common for specifying 0 to the operating system to translate to simply yielding your execution time slice to another thread. In the end, what this means is that No, instances of SFML's classes are not thread-safe by themselves. If you need thread-safety you must protect them. SFML comes with For more information on how to protect you shared data, refer to the official documentation.sf::sleep()
is merely a guideline, and not a contract. The longer you sleep for, the more accurate it will be. The shorter you sleep for, the less accurate it will be and to a certain extent more dependent on luck it will become.Is SFML thread-safe?
+ sf::Mutex
and sf::Lock
for this purpose but you can use other tools you may have available such as C++11's std::mutex
and std::lock_guard
as you see fit.Programming in General
What is RAII and why does it rock?
From 55a0b6f2e32d0fb3404c7272db5f43d553b1d7ba Mon Sep 17 00:00:00 2001
From: Adrien
Souvenez-vous : il faut toujours créer la fenêtre et gérer ses évènements dans le thread principal, pour un maximum de portabilité, comme expliqué dans le - tutoriel sur les fenêtres. + tutoriel sur les fenêtres.
- Vous pouvez dessiner et gérer les évènements d'une fenêtre dans deux threads différents car ces deux fonctionnalités sont complètement indépendantes.
- La classe n'est autrement pas thread-safe.
- En particulier, vous devez vous assurer que la fenêtre ne soit plus utilisée que dans un seul thread avant de la fermer.
+ L'exemple présentée ici n'est pas complètement thread-safe car un thread pourrait fermer la fenêtre pendant que l'autre l'utilise encore.
+ De manière générale, les objets SFML ne sont pas eux-mêmes thread-safes et vous devez vous-mêmes
+ protéger les données partagées.
+ Notez que vous pouvez dessiner et gérer les évènements d'une fenêtre dans deux threads différents sans soucis car ces
+ deux fonctionnalités sont complètement indépendantes.
- Note : you don't need to activate the window in the rendering thread, SFML does it automatically for you whenever it needs + Note that you don't need to activate the window in the rendering thread, SFML does it automatically for you whenever it needs to be done, as long as the OpenGL context is properly deactivate beforehand.
Remember to always create the window and handle its events in the main thread for maximum portability. This is explained in the - window tutorial. + window tutorial.
- You can draw and handle the events of a window in two different threads because these two functionalities dont share anything.
- The class is otherwise not thread-safe.
- In particular, you must ensure the window is only used in one thread before closing it.
+ The example show here is not completely thread-safe because a thread could close the window while another still uses it.
+ Generally speaking, SFML objects are not themselves thread-safe and you need to
+ protect the shared data yourself.
+ Note that you can draw and handle the events of a window in two different threads without issues because these
+ two functionalities are independent.
- Les instances des classes fournies par SFML ne sont en général pas thread-safe. Vous devez les protéger si vous les utilisez - dans plusieurs threads en même temps ! + Les objets SFML ne sont en général pas thread-safe, Vous devez les protéger si vous les utilisez dans plusieurs threads en même temps !
Il existe plusieurs outils de programmation pour vous aider à protéger les variables partagées et rendre votre code thread-safe, ils sont diff --git a/tutorials/2.6/system-thread.php b/tutorials/2.6/system-thread.php index f0377b47a..bff947a0c 100644 --- a/tutorials/2.6/system-thread.php +++ b/tutorials/2.6/system-thread.php @@ -223,7 +223,7 @@ classes are a good solution. If the operation is not thread-safe, it can lead to undefined behavior (ie. it might crash or corrupt data).
- Instances of classes defined by SFML are usually not thread-safe. You must protect them if you use them in multiple threads at the same time ! + SFML objects are usually not thread-safe, you must protect them to use them in multiple threads at the same time !
Several programming tools exist to help you protect shared data and make your code thread-safe, these are called synchronization primitives. Common ones
From 498dc56ab4bf8744c9031732dc57d6468a3ac7aa Mon Sep 17 00:00:00 2001
From: frayien
- SFML objects are usually not thread-safe, you must protect them to use them in multiple threads at the same time ! + SFML objects are usually not thread-safe. You must protect them to use them in multiple threads at the same time!
Several programming tools exist to help you protect shared data and make your code thread-safe, these are called synchronization primitives. Common ones
From 7b747d22ff495b3c86310a017536b304afe66388 Mon Sep 17 00:00:00 2001
From: frayien
- Les objets SFML ne sont en général pas thread-safe, Vous devez les protéger si vous les utilisez dans plusieurs threads en même temps ! + Les objets SFML ne sont en général pas thread-safe. Vous devez les protéger si vous les utilisez dans plusieurs threads en même temps !
Il existe plusieurs outils de programmation pour vous aider à protéger les variables partagées et rendre votre code thread-safe, ils sont
From bd1653d1c3a382f1dd5eef58cd08c319c4d76df8 Mon Sep 17 00:00:00 2001
From: frayien
- The example show here is not completely thread-safe because a thread could close the window while another still uses it.
+ The example shown here is not completely thread-safe because a thread could close the window while another still uses it.
Generally speaking, SFML objects are not themselves thread-safe and you need to
protect the shared data yourself. In the end, what this means is that No, instances of SFML's classes are not thread-safe by themselves. If you need thread-safety you must protect them. SFML comes with No, SFML objects are not thread-safe by themselves. If you need thread-safety you must protect them. SFML comes with For more information on how to protect you shared data, refer to the official documentation.
Note that you can draw and handle the events of a window in two different threads without issues because these
From f7546e457a8f179cae144c61d179521068231075 Mon Sep 17 00:00:00 2001
From: frayien sf::sleep()
is merely a guideline, and not a contract. The longer you sleep for, the more accurate it will be. The shorter you sleep for, the less accurate it will be and to a certain extent more dependent on luck it will become.Is SFML thread-safe?
- sf::Mutex
and sf::Lock
for this purpose but you can use other tools you may have available such as C++11's std::mutex
and std::lock_guard
as you see fit.sf::Mutex
and sf::Lock
for this purpose but you can use other tools you may have available such as C++11's std::mutex
and std::lock_guard
as you see fit.Programming in General