Good day. I want to use mutex in write | read mode when it reads any number of threads, and only writes one.

Here I advise shared_mutex, but it seems to be as soon as in C ++ 17 (at least in VS 2015 it is not there, only shared_lock).

How to properly make such a seizure?

    3 answers 3

    If boost is not suitable, then it remains to use OS-dependent solutions. Because You are using MSVC, then SRW lock should fit you. If you need cross-platform, then OS-dependent solutions can be wrapped in your class. But, generally speaking, in this case it is better to use boost and that's it.

      See pthread_rwlock_rdlock / pthread_rwlock_wrlock (and SEE ALSO in these mansions) from pthreads

      • He has the same Visual Studio, you what. - ixSci
      • @ixSci, indeed, Windows ... If in recent years pthreads have not been transferred there yet, then I feel sorry for him. (let him go to the normal system :-)) - avp
      • Windows has its own mechanisms that are not worse than pthreads - ixSci
      • @ixSci, I am sure that there is almost everything in Windows (even `\` as a path separator), but I don’t take it as a programming platform. - avp

      In the new C ++ standards (11, 14, 17), a lot of things migrate from boost 'a. Therefore, if you need the shared_mutex functionality, but it is not supported yet by your compiler, try using boost. In consequence, when shared_mutex appears in the standard, you simply refuse to boost.

      • I want to make a template without third-party lib. When C ++ 17 comes out, I will score on this program - Valera Pitanov