thread safe? #75
-
|
Hi, If I wanted to create a bot via some algorithm outside the behaviour-tree code, can I assume that methods like entity_manager->GetLocalPlayer()->SetPosition() and entity_manager->GetLocalPlayer()->GetPosition() and such are thread safe? I mean I know there's a GetMutex in LocalPlayer, if I acquire/release that, am I good to go? regards p.s. having lots of fun with your library! very easy to work with. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Short answer: yes, if you lock the mutex of the object you're using, you will (should) be fine. Examples for world, local_player and entity_manager. Long answer: the thread safety thing is quite old and I'd like to work on it someday (at least add some comments to the functions so it's clear that you should or not lock the corresponding mutex before calling it). It's nevertheless safe in the sense that all library internal calls lock the mutexes before doing stuff. However, it's not obvious when you should lock or not. For example, the |
Beta Was this translation helpful? Give feedback.
Short answer: yes, if you lock the mutex of the object you're using, you will (should) be fine. Examples for world, local_player and entity_manager.
Long answer: the thread safety thing is quite old and I'd like to work on it someday (at least add some comments to the functions so it's clear that you should or not lock the corresponding mutex before calling it). It's nevertheless safe in the sense that all library internal calls lock the mutexes before doing stuff. However, it's not obvious when you should lock or not. For example, the
EntityManger::AddEntityfunction already lock the mutex on its own (you shouldn't have to call this function except if you do something really exotic). Sim…