Code Monkey home page Code Monkey logo

Comments (3)

krizhanovsky avatar krizhanovsky commented on May 23, 2024

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.

jzulauf avatar jzulauf commented on May 23, 2024

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.

krizhanovsky avatar krizhanovsky commented on May 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.