Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use std::shared_mutex on Vista/Server 2008?

This is a follow-up question to TryAcquireSRWLock* and _WIN32_WINNT

As it seems there is a bug in the Windows SDK 8.1 and newer (up to at least the current 10.0.16299.0) making the methods TryAcquireSRWLockShared and TryAcquireSRWLockExclusive available for compilations targeting Windows Vista or Windows Server 2008. This causes applications containing calls to these methods being unable to execute on Windows Vista or Windows Server 2008 since they are ultimately only available starting from Windows 7 or Windows Server 2008 R2.

It seems that the implementation of std::shared_mutex in the Windows SDK 8.1 makes use of TryAcquireSRWLockShared and TryAcquireSRWLockExclusive. Thus using std::shared_mutex renders the application unable to execute on Windows Vista or Windows Server 2008.

The documentation also states

Warning

Beginning in Visual Studio 2015, the C++ Standard Library synchronization types are based on Windows synchronization primitives and no longer use ConcRT (except when the target platform is Windows XP). The types defined in <shared_mutex> should not be used with any ConcRT types or functions.

However, when using the platform toolset v140_xp the compiler complains about not knowing std::shared_mutex at all.

How can I use std::shared_mutex and still target Windows Vista or Windows Server 2008?

like image 691
sigy Avatar asked Mar 16 '18 16:03

sigy


1 Answers

I think you can't. But you can use alternate implementations. There's boost::shared_mutex. Or if you are using Qt, you can use QReadWriteLock.

like image 155
Alex Guteniev Avatar answered Nov 15 '22 06:11

Alex Guteniev