Code Monkey home page Code Monkey logo

Comments (8)

touil avatar touil commented on August 22, 2024

Did you read the actual code and go through the "rabbit hole" or do you just "think" it should be "better" this way?
More precisely, did you read this line?

https://github.com/airspy/airspyone_host/blob/master/libairspy/src/airspy.c#L832

from airspyone_host.

johanhedin avatar johanhedin commented on August 22, 2024

Did you read the actual code and go through the "rabbit hole" or do you just "think" it should be "better" this way? More precisely, did you read this line?

https://github.com/airspy/airspyone_host/blob/master/libairspy/src/airspy.c#L832

Realized the wording "uninitialized" is wrong on my side. I should have expressed it as "calling ptherad_jonin() with a thread id of zero causes segfault".

from airspyone_host.

touil avatar touil commented on August 22, 2024

I am yet to see a segfault with that code. pthread_join returns ESRCH with thread_id 0, which is perfectly fine.

from airspyone_host.

johanhedin avatar johanhedin commented on August 22, 2024

The following program segfaults on CentOS 6, CentOS 7 and Fedora 39 but works on Raspberry Pi OS (Bookworm and Buster). So not all pthread implementations on all platforms handles a thread id of 0 to pthread_join() as ESRCH.

#include <pthread.h>

int main(int argc, char **argv) {
    pthread_t thread = 0;

    pthread_join(thread, NULL);

    return 0;
}

Compiled with:

$ gcc -o out segfault.c -lpthread

from airspyone_host.

touil avatar touil commented on August 22, 2024

Can't reproduce on any up to date Linux on any CPU I tested (x86, x86_64, ARMHF, AARCH64.) Maybe you just highlighted a problem in your distro? I'm sure you can find more broken Linux stuff if you bring a distro from the 90s.
Yet, the "fix" you proposed still doesn't work because of the many possible ways libusb can fail. Someone has to go through that rabbit hole and do the actual investigation work. Maybe a simple check can work for the fossilized distros. Or maybe we should exclude them to keep a sane code base.

Try it: https://onlinegdb.com/VQarzj8G-

from airspyone_host.

johanhedin avatar johanhedin commented on August 22, 2024

The reference to the old CentOS distros was just to show that the behavior of pthread_join() has been consistent for a very long time in the RHEL-line of distros. Fedora 39 is a recent distro and the issue I'm raising is not about fossilized distros.

As far as I can read, passing anything other than a joinable thread id as the first argument to pthread_join() is undefined behavior. Distros/implementations have apparently made different choices how to handle this (Debian/Ubuntu: return ESRCH, RHEL-line: segfault) . Nothing odd about that but code using pthread should be written with this in mind. In this case not calling pthread_join() with a invalid/NULL thread id or a thread id that was previously joined.

I'll create a PR with a check.

from airspyone_host.

touil avatar touil commented on August 22, 2024

This should be it.

from airspyone_host.

johanhedin avatar johanhedin commented on August 22, 2024

Tnx.

from airspyone_host.

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.