C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Float the idea: First-class effect annotations and resource contracts for C++

From: Thiago Macieira <thiago_at_[hidden]>
Date: Mon, 08 Jun 2026 09:13:19 -0700
On Monday, 8 June 2026 04:50:20 Pacific Daylight Time Bjorn Reese via Std-
Proposals wrote:
> > A related concept that is very important in embedded systems is
> > "re-entrant". A function is "re-entrant" if there can be more than one
>
> The standard calls this "signal-safe" -- see [support.signal] para 3.

That's not exactly the same concept.

A function is thread-safe if two threads can enter it at the same time. A
simple way to implement this is to have a mutex so that only one can access
common resources at a time.

A function is reentrant if it can be entered more than once at the same time.
If it's reentrant and thread-safe, it can be reentered by any thread,
including the current, via recursion. It can also be reentrant but not thread-
safe. But here's an important catch: this expects entering to happen at normal
ABI boundaries of the *current* thread.

A signal-safe function is one that can be reentered asynchronously in the same
thread from any point in the function of the function, including any functions
it calls. That excludes calling any functions that eventually end up in
malloc(), because that is thread-safe but not signal-safe. In fact, any
functions locking mutexes are usually not signal-safe. That's what the
"nonblocking" attribute means.

It's a horrible name because it collides with O_NONBLOCK.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel Data Center - Platform & Sys. Eng.

Received on 2026-06-08 16:13:25