Skip to content

Our pthread_kill implementation is incorrect, this API is not for killing threads, but sending signals to them #14872

@sbc100

Description

@sbc100

pthread_kill, just like kill, is for sending signal to processes. What is more it seems to specifically not be capable of killing an individual pthread, only directing a signal to be received on a specific thread.

The only way a thread can be killed is if vulunarily exits, and sending a signal to a thread is just one way to ask it to exit. If one actually send SIGKILL to a thread it will bring down the entire process, not that just thread.

See https://stackoverflow.com/questions/34258271/pthread-kill-kills-not-just-a-thread-but-the-whole-program for some discussion of this.

We could make a fake implementation of pthread_kill but we would only be able to deliver signals to threads that yield in some way and not busy-looping. It seems that we can really only support cooperative receiving of signal which means we probably can't do better than pthread_cancel if we want to try to bring down a running thread.

What is more the current test for pthread_kill is currently disabled on chrome because it causes the tab to hang (i.e. worker.terminate() simply doesn't work for busy-looping threads). See:

@no_chrome('pthread_kill hangs chrome renderer, and keep subsequent tests from passing')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions