Comments (3)
Hi!
I use unsigned long, which is 64 bits in size, exactly to avoid overflow issues as well as additional cost on integer overflow management. If we suppose a 3Ghz processor incrementing unsigned long variable each tick, then it'll require almost 195 years to overflow the variable
$ perl -le 'print +(~0 / 3_000_000_000 / 3600 / 24 / 365)'
194.980805785024
So we can safely suppose that we're safe from integer overflows.
from blog.
for x64, you're certainly correct. for x86 32, long is 32 bits, at least on compilers with which I'm familiar, and people still build and run 32 bit code, At the rate of about 100ns per push or pop operation I measured for boost::lockfree in my testing, would overflow in about 20 minutes.
Probably the simplest fix is to detect 32bit at compile time and typedef the counters to ulonglong... or just use uint64_t to begin with :) -- though it would be interesting to bench the overflow management logic versus the additional width.
BTW -- brilliant article, clearest exposition on a lock-free design I've read
from blog.
The queue is designed specially for x86_64 and we ever check this at compile time https://github.com/krizhanovsky/NatSys-Lab/blob/master/lockfree_rb_q.cc#L25 .
And thanks for good words ;)
from blog.
Related Issues (5)
- two question HOT 8
- Why conflicts happen in the case of independent location HOT 7
- lockfree_rb_q.cc volatile HOT 6
- Licensing HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blog.