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

流过昼夜 提交于 2019-12-10 12:52:25

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/49325813/how-to-use-stdshared-mutex-on-vista-server-2008

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!