Is a mutex capable of performing this

I have a situation where I have multiple threads accessing the clipboard and performing an action with some sleeps. Basically I don't want to copy the wrong thing to the clipboard and perform something in an incorrect fashion.

Currently, I have an idea of using a mutex to lock a std::string variable and store the required data in it, then to the clipboard. After I finish the action, I unlock it. Then the other thread accesses the variable, then clipboard, and action.

As I have never used a mutex, my question is - will it work by just doing the above?

I'm using the following library to manage the clipboard: https://github.com/dacap/clip



from Recent Questions - Stack Overflow https://ift.tt/31va4aq
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Hibernate Search - Elasticsearch with JSON manipulation

Spring Elasticsearch Operations