Skip to content

thread safe? #74

Closed
Closed

Description

@folkertvanheusden

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.

Activity

  1. adepierre commented on Feb 9, 2022

    @adepierre
    Owner

    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::AddEntity function already lock the mutex on its own (you shouldn't have to call this function except if you do something really exotic). Similarly, a few functions return copies of the objects so you can unlock the mutex as soon as you get the object, but some other return pointers/references, forcing you to keep the mutex locked while you're using it.

  2. Repository owner locked and limited conversation to collaborators on Feb 9, 2022
  3. converted this issue into a discussion #75 on Feb 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions