Hi,
According to the issue, I wonder If you want to protect a shared resource from simultaneous access by multiple threads or processes? If so, I suggest you could try to use a mutex Class. Each thread must wait for ownership of the mutex before it can execute the code that accesses the shared resource.
I suggest you could try to construct a mutex object. by std::mutex, and then call the member function lock() to lock the mutex, call the member function unlock() to unlock it.
You could also try to use lock_guard Class.
Best Regards,
Jeanine
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.