Coder Social home page Coder Social logo

Comments (4)

nephatrine avatar nephatrine commented on August 20, 2024 2

It's not just a consequence of optimization, the lock is literally right before the destroy call in the code. No amount of sleeping will change that.

        /* Because we allocate pool->threads after initializing the
           mutex and condition variable, we're sure they're
           initialized. Let's lock the mutex just in case. */
        pthread_mutex_lock(&(pool->lock));
        pthread_mutex_destroy(&(pool->lock));

https://linux.die.net/man/3/pthread_mutex_destroy
https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_destroy.html

Attempting to destroy a locked mutex results in undefined behavior.

I'd imagine that this is actually "harmless" in practice, but for what reason is it being locked before being destroyed? If we need that lock there, then just inserting an unlock immediately afterwards would suffice to comply with the POSIX standard. The only concern I see is if you think something else could lock it between the unlock and the destroy, but if you've got other threads still trying to use the mutex at that point then you've got bigger issues.

from concord.

lcsmuller avatar lcsmuller commented on August 20, 2024

I suspect that this is not an actual bug, but a consequence of pthread's optimization, see: https://stackoverflow.com/a/68514238

I had also come across a similar error when running my application under valgrind, but after some research I came to the conclusion that it's a harmless "leak". You can probably circumvent it by having your process sleep for a little while before termination. If you believe that your issue is unrelated to this, feel free to re-open this issue.

from concord.

lcsmuller avatar lcsmuller commented on August 20, 2024

I'll take a better look at this once I get home, I may have mixed up your issue with something else I was having. My bad for just assuming.

It's not just a consequence of optimization, the lock is literally right before the destroy call in the code. No amount of sleeping will change that.

In the meantime, can you confirm that changing the ordering fixes the issue? If so, could you please open a PR fixing it?

from concord.

lcsmuller avatar lcsmuller commented on August 20, 2024

Just to give a bit of a context, the issue arises from how this third-party threadpool lib manages its clean up. We can either look for an alternative (C99 compliant) threadpool implementation, write our own, or fix this one (and send a fix PR to the original's out of courtesy).

from concord.

Related Issues (20)

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.