Skip to content

Sporadic Deadlock When Using Async and Yield #90

Description

@Jason-KChen

I am running into a possible deadlock scenario when running the attached code without HCLIB_LOCALITY_FILE and with two workers.

The promises and waits were executed just fine but it seems like the tasks themselves never finish for some reason. I am able to reproduce this issue about 7 out of 10 runs on my machine. @srirajpaul was also able to reproduce this.

#include <chrono>
#include <cstdint>
#include <iostream>
#include <stdlib.h>
#include <thread>

#include "hclib_cpp.h"

int main(int argc, char** argv) {
    const char* deps[] = { "system" };
    hclib::launch(deps, 1, []() {
        hclib::finish([]() {
            hclib::async([]() {
                hclib::promise_t<int>* x = new hclib::promise_t<int>();
                hclib::promise_t<int>* y = new hclib::promise_t<int>();

                hclib::async([y] {
                    hclib::yield();
                    y->put(1);
                });

                hclib::async([x] {
                    x->get_future()->wait();
                });

                y->get_future()->wait();
                x->put(10);
            });
        });
        std::cout << "all finished " << std::endl;
    });
    return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions