Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run_as_os_thread locks up #2991

Closed
hkaiser opened this issue Nov 6, 2017 · 1 comment

Comments

Projects
None yet
1 participant
@hkaiser
Copy link
Member

commented Nov 6, 2017

Maciej Brodowicz reported:

The following code locks up even if it shouldn't:

//  Copyright (c) 2017 Maciej Brodowicz
//
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <hpx/hpx_init.hpp>
#include <hpx/hpx.hpp>
#include <hpx/runtime/threads/run_as_os_thread.hpp>

#include <iostream>
#include <mutex>
#include <thread>

std::mutex mtx;

void locker()
{
    std::cout << std::this_thread::get_id() << ": about to lock mutex\n";
    std::lock_guard<std::mutex> lock(mtx);
    std::cout << std::this_thread::get_id() << ": mutex locked\n";
}

int hpx_main()
{
    {
        std::cout << std::this_thread::get_id() << ": about to lock mutex\n";
        std::lock_guard<std::mutex> lock(mtx);
        std::cout << std::this_thread::get_id() << ": mutex locked\n";

        std::cout << std::this_thread::get_id() << ": about to run on io thread\n";
        hpx::threads::run_as_os_thread(locker);
        //sleep(2);
    }
    std::cout << std::this_thread::get_id() << ": exiting\n";

    return hpx::finalize();
}

int main(int argc, char **argv)
{
    return hpx::init(argc, argv);
}
@hkaiser

This comment has been minimized.

Copy link
Member Author

commented Nov 6, 2017

The problem is that currently our parallel::execution::io_pool_executor (used by run_as_os_thread) will wait in its destructor for all tasks to finish. Since the task scheduled by this executor is never returning (it's waiting for the mutex to become available (will happen only after the executor has been destroyed) the threads lock up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.