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

[PAL/vm-common] Hang on a detached thread #43

Open
dimakuv opened this issue Aug 6, 2024 · 0 comments
Open

[PAL/vm-common] Hang on a detached thread #43

dimakuv opened this issue Aug 6, 2024 · 0 comments

Comments

@dimakuv
Copy link

dimakuv commented Aug 6, 2024

Reproducer:

#include <stdio.h>

#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>

typedef struct {
    int seconds;
} thread_data_t;

void* thread_func(void* arg) {
    thread_data_t* data = (thread_data_t*)arg;
    sleep(data->seconds);
    free(data);  // Free the allocated memory for thread data
    printf("exiting!\n");
    exit(2);
}

int main(void) {
    printf("Hello, world\n");

    pthread_t thread;
    thread_data_t* data = malloc(sizeof(thread_data_t));
    if (data == NULL) {
        perror("Failed to allocate memory");
        return 1;
    }
    data->seconds = 2;

    if (pthread_create(&thread, NULL, thread_func, data) != 0) {
        perror("Failed to create thread");
        free(data);
        return 1;
    }

    pthread_detach(thread);
    while(1);
    return 0;
}

The hang happens here:

while (!check_last_thread(/*mark_self_dead=*/false)) {

Reported by @dimstav23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant