From: IMMING <2465853002@qq.com>
To: musl <musl@lists.openwall.com>
Subject: [musl] A question about the implementation of pthread_create and start
Date: Mon, 27 May 2024 20:22:42 +0800 [thread overview]
Message-ID: <tencent_FD8896C7303E60BA2F965266BABB1E588009@qq.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 2369 bytes --]
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?
[-- Attachment #2: Type: text/html, Size: 35978 bytes --]
next reply other threads:[~2024-05-27 12:23 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-27 12:22 IMMING [this message]
2024-05-27 14:56 ` Markus Wichmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tencent_FD8896C7303E60BA2F965266BABB1E588009@qq.com \
--to=2465853002@qq.com \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).