|
Message-ID: <tencent_FD8896C7303E60BA2F965266BABB1E588009@qq.com>
Date: Mon, 27 May 2024 20:22:42 +0800
From: "IMMING" <2465853002@...com>
To: "musl" <musl@...ts.openwall.com>
Subject: A question about the implementation of pthread_create and start
Hi, I would like to ask a question about the implementation of pthread_create and start (musl v1.2.5)
My question is as follows, here is the code:
-----------------
int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict attrp, void *(*entry)(void *), void *restrict arg)
...
if (ret < 0) {
ret = -EAGAIN;
} else if (attr._a_sched) {
ret = __syscall(SYS_sched_setscheduler,
new->tid, attr._a_policy, &attr._a_prio);
if (a_swap(&args->control, ret ? 3 : 0) == 2) <- line 1
__wake(&args->control, 1, 1); <- line 2
if (ret)
__wait(&args->control, 0, 3, 0); <- line 3
}
...
-----------------
static int start(void *p)
...
struct start_args *args = p;
int state = args->control;
if (state) {
if (a_cas(&args->control, 1, 2) == 1) <- line 4
__wait(&args->control, 0, 2, 1); <- line 5
if (args->control) {
__syscall(SYS_set_tid_address, &args->control); <- line 6
for (;;) __syscall(SYS_exit, 0); <- line 7
}
}
__syscall(SYS_rt_sigprocmask, SIG_SETMASK, &args->sig_mask, 0, _NSIG/8);
...
-----------------
I think the calling route should be like this:
1.line 4(child thread)
2.line 5(child thread wait)
3.line 1(parent thread if SYS_sched_setscheduler false)
4.line 2(parent thread wake child thread)
5.line 3(parent thread wait if SYS_sched_setscheduler false) <- Problem point
6.line 6(child thread)
7.line 6(child thread exit)
My question is, if SYS_sched_setscheduler returns an error (a non-zero value), the parent thread will remain in a wait state and I have not found a way to wake it,
which will cause the parent thread to remain stuck in the pthread_create function and unable to return
1.Is my analysis process correct?
2.Is the situation where the parent thread gets stuck in the waite as expected?
Content of type "text/html" skipped
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.