Skip to content

Not abort on pthread_create and pthread_join for single thread build #25738

@eagleoflqj

Description

@eagleoflqj

I've been creating patches for 3rd-party library to convert thread creation to a normal function call and remove thread join: mozc libchewing fcitx5-chinese-addons
I know the existence of real pthread support but that needs COEP and COOP. I know these 2 headers can be set by service worker, but I'm creating a JS library that can hopefully be embedded to any website, including those already have their own service worker, so single thread build is the only option for me.
It's possible to not abort on pthread_create and pthread_join, but instead, do a normal function call for create, and return 0 for join.
I've tested with code below

#include <thread>
#include <iostream>

void hello() {
    std::cout << "Hello from thread!" << std::endl;
}

int main() {
    std::thread t(hello);
    t.join();
    return 0;
}
em++ hello.cpp # The a.out.js can print normally without -pthread

This is for sure a behavior change, but I hope in a good way. Any concerns?

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