This is the code that I used as the basis for my articles in the Game Programming Gems series. I wrote the following articles, both of which were included in Best of Game Programming Gems.
This code is targetted toward Visual C++ 2015, though it should also work with GCC. The master branch serves as the up-to-date version of this code. The gems_bugfix branch contains the code and projects as they were written for the Gems books, with minor bug fixes as necessary.
The Mersenne Twister code was written in a tutorial style, and is not optimized for speed. C++03 was the latest version of C++ available when this code was originally written. C++11 now includes the Mersenne Twister as one of several new random number libraries available by default.
The Lock-Free code is reasonably good, though I caution any user against using any lock-free algorithms, as that style of code is exceptionally difficult to debug, and often can perform worse than the equivalent code using locks. It is fun as a mental exercise, but often difficult for many programmers to avoid the temptation of using it in practice.
As a case-in-point, this lock-free queue does have a bug in
LockFreeQueue<T>::Add()
. The CAS between _pTail->pNext and nullptr isn't
correct as that element isn't guaranteed to still be in the queue. I don't
have a fix, and I can't reproduce the issue, though it has been reported on
Xbox 360 and appears to be a bug independent of architecture.
Toby Jones (www.turbohex.com, ace.roqs.net)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。