Skip to content

std::async will hang if no threads are available #8988

Closed
@VirtualTim

Description

@VirtualTim

No idea why this is different from regular threads.

#include <thread>
#include <future>
#include <iostream>

int main(int argc, char** argv) {
  //works
  std::thread([] {
    std::cout << "Thread ID: " << std::this_thread::get_id() << std::endl;
  }).detach();
  
  //hangs
  std::async([] {
    std::cout << "Thread ID: " << std::this_thread::get_id() << std::endl;
  });
}

Compile with: emcc test.cpp -std=c++11 -s USE_PTHREADS=1 -o test.html to see the issue.
Compile with: emcc test.cpp -std=c++11 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=2 -o test.html to make this work as expected.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions