Replies: 1 comment 1 reply
-
|
You can use atomic variables for simple primitive data types: #include <atomic>
std::atomic_int some_shared_var;
// in a writer function..
some_shared_var = std::rand();
// in a reader function..
auto value = some_shared_var; // or .load()Or use mutexes and locks for containers or complex data types: #include <shared_mutex>
std::shared_mutex some_shared_var_mtx;
// in a writer function..
std::scoped_lock lock(some_shared_var_mtx);
some_shared_var = "complex";
// in a reader function..
std::shared_lock lock(some_shared_var_mtx);
auto value = some_shared_var; |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
What is the best way in terms of drogon to make access to shared resources safe?
Let's consider following example
As I understood threading model controller handler is called from arbitrary worker thread, hereof follows it must be completed with some synchronisation.
What is the best practices?
I suppose it's alright to move read to loop something like this.
But maybe are there any better practices?
Beta Was this translation helpful? Give feedback.
All reactions