Coder Social home page Coder Social logo

Comments (6)

hkaiser avatar hkaiser commented on July 26, 2024

It may be better to store the thread id for hpx_main as a non-reference counting id (i.e., threads_id_type) in this case.

from hpxc.

rtohid avatar rtohid commented on July 26, 2024

Thank you, @Pansysk75. If I remember correctly, the issue was in hpxc_setspecific, where the thandle would be null for hpx_main, and what you're referring to was supposed to be the workaround.

from hpxc.

Pansysk75 avatar Pansysk75 commented on July 26, 2024

@hkaiser I was looking at a fix using hpx::threads::add_thread_exit_callback() to add a callback function to hpx_main. The callback doesn't seem to get called, even though hpx_main terminates :((
Should that work in theory, or am I not supposed to use it like that?

thread_handle(hpx::threads::thread_id_ref_type id)
:
. . .
{
        auto on_completion = [thandle = this]() {
            std::cout << "This print is not printing" << std::endl;
            // Signal completion
            thandle->promise.set_value(nullptr);
            int r = --thandle->refc;
            if (r == 0)
            {
                delete thandle;
            }
        };

        if (!hpx::threads::add_thread_exit_callback(id.noref(), on_completion))  <--------
        {
            // Failed to add callback because the hpx thread has terminated
            // This throw does not happen
            throw;
        }
}

The rationale of doing this, is to retain the ability to have hpxc-thread-data even for threads not launched through the hpxc API, and have that data be deleted when the thread finished (just like we do for the other threads spawned with hpxc_thread_create)

from hpxc.

hkaiser avatar hkaiser commented on July 26, 2024

@Pansysk75 now I'm confused. I thought the whole problem was that hpx_main was not terminating, in which case it would be logical for the callback to never be called...

from hpxc.

Pansysk75 avatar Pansysk75 commented on July 26, 2024

@Pansysk75 now I'm confused. I thought the whole problem was that hpx_main was not terminating, in which case it would be logical for the callback to never be called...

Ah, it's terminating, holding the reference just keeps it from getting deleted after termination

from hpxc.

hkaiser avatar hkaiser commented on July 26, 2024

@Pansysk75 now I'm confused. I thought the whole problem was that hpx_main was not terminating, in which case it would be logical for the callback to never be called...

Ah, it's terminating, holding the reference just keeps it from getting deleted after termination

Well, in this case the callback should be invoked (see: https://github.com/STEllAR-GROUP/hpx/blob/e7c31a49dd4e550a61134e498f3ecfb585d201cb/libs/core/threading_base/include/hpx/threading_base/register_thread.hpp#L72)

from hpxc.

Related Issues (8)

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.