简体   繁体   中英

A thread barrier class using only Win32 APIs

I am trying to synchronize a bunch of threads using a thread barrier. I tried to use Boost::barrier to do it but I have run into some linking issues : Compiling Bullet physics and Boost together as static libraries

So while it may take some time to get it resolved, I have decided to proceed with my own thread barrier class. The barrier mechanism needs to be low latency as I will use it for a real time simulator. I have looked at some options here :

Writing a (spinning) thread barrier using c++11 atomics

However it uses C++ atomics which I think is not mature enough in Visual Studio 2010. I am trying to pull together my own thread barrier class using only win32 API and I was looking at this :

http://adilevin.wordpress.com/category/multithreading/

I was wondering if anyone has a better suggestion. I would rather not have external library dependencies and use only C++ and the win32 api for now.

If you're okay with using straight Win32 API (and it seems you are) then you can just roll your own atomic<> template using the Win32 atomics:

InterlockedExchange InterlockedCompareExchange etc...

Then when you have better support for atomics in the IDE (Visual Studio 2011?) you can swap your own template out for the one in the standard library.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM