public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "adhemerval.zanella at linaro dot org" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sourceware.org
Subject: [Bug libc/30558] SIGEV_THREAD is badly implemented
Date: Mon, 19 Jun 2023 22:51:04 +0000	[thread overview]
Message-ID: <bug-30558-131-QiUVofeIyh@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-30558-131@http.sourceware.org/bugzilla/>

https://sourceware.org/bugzilla/show_bug.cgi?id=30558

--- Comment #16 from Adhemerval Zanella <adhemerval.zanella at linaro dot org> ---
(In reply to Stas Sergeev from comment #15)
> > Indeed afaik Linux reset the overrun time on each sigtimedwait syscall.
> 
> Its not linux, its posix who defined
> timer_getoverrun() in an entirely crazy
> way of measuring underruns between signal
> queue and dequeue.
> Linux is at least making this more or
> less viable by actually measuring between
> dequeues only.
> Linux itself clearly says how it see it
> implemented: timerfd, where read() just
> resets the overrun count. Linux is written
> by skilled programmers, while posix is
> written by a mediocre doc-writers.
> 
> > In fact, POSIX also advises against it on the timer_settime application
> > because of the concurrent stack usage issue [2].
> 
> Quote:
> 
> [EINVAL]
>     The it_interval member of value is not zero and the timer was created
> with notification by creation of a new thread (sigev_sigev_notify was
> SIGEV_THREAD) and a fixed stack address has been set in the thread attribute
> pointed to by sigev_notify_attributes.

This is defined as 'may fail', which does not bind the implementation to the
required semantic of one thread per time expiration.

> 
> So concurrent stack usage is explicitly
> disallowed, which means a detached thread
> per timer tick, as was said in the prev
> quote that I provided.
> 
> > But POSIX explicitly states that the thread is *not* joinable
> > ("In neither case is it valid to call pthread_join()")
> 
> I don't think it means not joinable.
> I think it means only that the _user_
> should never call pthread_join() on
> such thread. Presumably he could do
> that by exporting its pthread_self()
> through the global variable.
> I think the thread itself can be joinable,
> and as long as the user doesn't call
> pthread_join() on it, things are good
> and glibc itself *can* (and should)
> call pthread_join() internally on a
> timer destruction.

This wording is a user-visible API, so not being joinable it means that the
caller can not call any pthread interface meant for joinable threads (I think
POSIX is pretty clear in this regard).  As I said, making the thread joinable
implies a lot of caveats for the API, and that's why POSIX is explicit about
it.

And glibc does not need to join the thread, if it is created in detached mode
the thread itself will be responsible for handling any allocated resources and
an additional synchronization with any global state.

> 
> > In fact, from the Austin issue [1] the next POSIX 2018 defined that providing
> > a pthread_attr_t with joinable state is undefined-behavior [2];
> 
> This only confirms that posix is
> written by idiots. But such an obvious
> fact probably doesn't need so many
> confirmations. :)

Afaik POSIX only defines API after a de-facto implementation exactly to avoid
adding non-tested ones. But I would like to avoid bad-mouthing other groups in
bug reports.

> 
> > so I am even more inclined to *not* move to make it implementation-defined.
> 
> I am definitely not "insisting" in
> any way. I am only pointing out that
> any other approach is even more problematic.
> But at the end, any improvement is better
> than the current mess.
> 
> What do you think about opening a DR to
> The OpenGroup? If it would be me, I wouldn't
> resist saying who they are, so its better
> be you. :) Though I don't think timer_create()
> API can be vindicated by a DR or 2.
> getoverrun is also completely broken, and
> so on. Why I still have to use it, is only
> because of freebsd. On linux my app uses
> timerfd, of course and for sure. I am trying
> to avoid the brain-damaged posix APIs on
> linux, but there comes freebsd...

A DR for what exactly? I think the current definition does allow one-thread per
timer without extra thread per timer expiration (musl implements it and Rich is
*very careful* about following standards) so I don't see which additional
clarification we need on this topic.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

  parent reply	other threads:[~2023-06-19 22:51 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-15 19:36 [Bug libc/30558] New: " stsp at users dot sourceforge.net
2023-06-15 21:04 ` [Bug libc/30558] " adhemerval.zanella at linaro dot org
2023-06-16  2:23 ` stsp at users dot sourceforge.net
2023-06-16  6:44 ` stsp at users dot sourceforge.net
2023-06-16  7:29 ` stsp at users dot sourceforge.net
2023-06-16  7:51 ` stsp at users dot sourceforge.net
2023-06-16 11:44 ` stsp at users dot sourceforge.net
2023-06-19 17:41 ` adhemerval.zanella at linaro dot org
2023-06-19 18:54 ` stsp at users dot sourceforge.net
2023-06-19 19:33 ` adhemerval.zanella at linaro dot org
2023-06-19 19:48 ` stsp at users dot sourceforge.net
2023-06-19 20:14 ` adhemerval.zanella at linaro dot org
2023-06-19 20:26 ` stsp at users dot sourceforge.net
2023-06-19 21:15 ` adhemerval.zanella at linaro dot org
2023-06-19 21:21 ` adhemerval.zanella at linaro dot org
2023-06-19 21:58 ` stsp at users dot sourceforge.net
2023-06-19 22:51 ` adhemerval.zanella at linaro dot org [this message]
2023-06-20  4:14 ` stsp at users dot sourceforge.net
2023-06-20 12:21 ` adhemerval.zanella at linaro dot org
2023-06-20 12:49 ` stsp at users dot sourceforge.net
2023-06-20 13:01 ` adhemerval.zanella at linaro dot org
2023-06-20 13:13 ` stsp at users dot sourceforge.net
2023-06-21  3:19 ` stsp at users dot sourceforge.net
2023-06-21 14:32 ` adhemerval.zanella at linaro dot org
2023-06-21 14:41 ` stsp at users dot sourceforge.net
2023-06-21 14:43 ` adhemerval.zanella at linaro dot org
2023-06-21 14:52 ` stsp at users dot sourceforge.net
2023-06-21 15:07 ` adhemerval.zanella at linaro dot org
2023-06-22  2:57 ` bugdal at aerifal dot cx
2023-06-22  5:23 ` stsp at users dot sourceforge.net
2023-06-23 18:34 ` adhemerval.zanella at linaro dot org
2023-06-24 17:03 ` crrodriguez at opensuse dot org

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=bug-30558-131-QiUVofeIyh@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@sourceware.org \
    /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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).