Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<typename T> struct State
- {
- std::map<std::string, T> statedata;
- static std::mutex mux_state;
- ...
- void update(std::string k, T t)
- {
- while (!mux_state.try_lock()) timeoutdelay(TOD_UPDATE);
- ..do update..
- mux_state.unlock();
- }
- ...
- T read(std::string k)
- {
- while (!mux_state.try_lock()) timeoutdelay(TOD_READ);
- T t=statedata[k];
- mux_state.unlock();
- return t;
- }
- ...
- }
- ...
- State<mytype> state;
- ...
- ..from thread_1() randomly
- state.update(..)
- ...
- ..from thread_2() randomly
- state.read(..)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement