Bye, Dragan
--
Dragan Cvetkovic,
To be or not to be is true. G. Boole No it isn't. L. E. J. Brouwer
For example, a routine might be made async-signal safe simply by masking all
signals during operation. (It's "safe" from a signal handler because the
handler cannot have interrupted the activity of another invocation of that
routine.) This doesn't mean it's thread-safe.
Of course, that's the comp.programming.threads answer, dealing with the
nature of the definitions. You might get a different answer based on the
formal usage of the terms in Solaris documentation. (Though I don't think
so.)
--
| Hewlett-Packard Company Tru64 UNIX & VMS Thread Architect |
| My book: http://www.awl.com/cseng/titles/0-201-63392-2/ |
\----[ http://homepage.mac.com/dbutenhof/Threads/Threads.html ]---/
Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
Safe means that no "bad" things happen (like memory corruption or
program crashes; if one thread uses lseek() and the other write(),
strange things will happen yet both lseek() and write() are safe.)
Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
> >> If a routine is Async-Signal-Safe is it also Safe? Is
> >> Async-Signal-Safe a superset of Safe? I cannot tell this from the man
> >> page for attributes(5).
> >The aforementioned man page mentions close(2) as an counterexample.
> No, it does not. It says that close(2) is "Safe" but that you can
> still use it unsafely.
> Safe means that no "bad" things happen (like memory corruption or
> program crashes; if one thread uses lseek() and the other write(),
> strange things will happen yet both lseek() and write() are safe.)
Btw, if I do close(fd) in one thread and do write(fd, ...) in the other one
some time later, I should get EBADF in the other one, shouldn't I?
Bye, Dragan
--
Dragan Cvetkovic,
To be or not to be is true. G. Boole No it isn't. L. E. J. Brouwer
> > >> If a routine is Async-Signal-Safe is it also Safe? Is
> > >> Async-Signal-Safe a superset of Safe? I cannot tell this from the man
> > >> page for attributes(5).
> > >The aforementioned man page mentions close(2) as an counterexample.
> > No, it does not. It says that close(2) is "Safe" but that you can
> > still use it unsafely.
> > Safe means that no "bad" things happen (like memory corruption or
> > program crashes; if one thread uses lseek() and the other write(),
> > strange things will happen yet both lseek() and write() are safe.)
> Hm, I'll say you are right but only because lseek(2)/write(2)/close(2) are
> used for their side effects, not for the actual values they produce ...
> Btw, if I do close(fd) in one thread and do write(fd, ...) in the other one
> some time later, I should get EBADF in the other one, shouldn't I?
Joe Seigh
Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
Well, are you sure about that? Because it is a little different fromQuote:> For example, a routine might be made async-signal safe simply by masking all
> signals during operation. (It's "safe" from a signal handler because the
> handler cannot have interrupted the activity of another invocation of that
> routine.) This doesn't mean it's thread-safe.
By masking signals, you can achieve signal safety, of course. But is
it the way defined in POSIX? I don't have the standard at hand. But
I am a little suspicious.
Regards,
LG
So perhaps if you block signals and then lock a mutex, the async signal
safe function could conceivably modify global data; but I don't think I
want to go there.
Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
> Well, are you sure about that? Because it is a little different from
> what I know. The async-signal-safe is also named reentrant, meaning it
> uses no shared data, only stack variables are used. So it is safe to
> be called anywhere, ig. inside signal handlers. To reach MT-safe, you
> can merely use some sync objects, mutexes, whatever, but that does not
> necessarily lead to signal safe. The routine printf() is not signal
> safe, but MT-safe, and write() is signal-safe. Solaris manual
> explicitely specifies routiine signal safety.
> By masking signals, you can achieve signal safety, of course. But is
> it the way defined in POSIX? I don't have the standard at hand. But
> I am a little suspicious.
Few, if any, of the POSIX and XSH async-signal safe functions can be made
fully reentrant, because they generally affect shared data: for example
open, close, read, and write modify file descriptors, and that modification
needs to be synchronized.
In any case, this is diverging from the topic. The original question
regarded an interpretation of terminology. While the question specifically
referenced Solaris man pages, it wasn't at all clear what the INTENT of the
question might be, so a general explanation seemed in order. I said that I
don't have the exact Solaris definition (which is related to but not
identical to the POSIX definition) handy. I also said that in general one
could expect that async-signal safe was also [thread] safe, but gave a
cautionary example of how this isn't necessarily so.
--
| Hewlett-Packard Company Tru64 UNIX & VMS Thread Architect |
| My book: http://www.awl.com/cseng/titles/0-201-63392-2/ |
\----[ http://homepage.mac.com/dbutenhof/Threads/Threads.html ]---/
You're not alone. There's at least two ofunctions (tcflush(3) andQuote:> If a routine is Async-Signal-Safe is it also Safe? Is
> Async-Signal-Safe a superset of Safe? I cannot tell this from the man
> page for attributes(5).
On the other hand, the following excerpt from the attributes(5) man
page:
Async-Signal-Safe refers to particular library
routines that can be safely called from a signal
handler. A thread that is executing an Async-
Signal-Safe routine will not deadlock with itself
if interrupted by a signal. Signals are only a
problem for MT-Safe routines that acquire locks.
Signals are disabled when locks are acquired in
Async-Signal-Safe routines. This prevents a signal
handler that might acquire the same lock from
being called.
and in particular its third statement, may be interpreted as a hint at
that Async-Signal-Safe are indeed MT-Safe, and thus Safe, because:
An MT-Safe
library must permit a reasonable amount of
concurrency. (This definition's purpose is to give
precision to what is meant when a library is
described as Safe. The definition of a Safe
library does not specify if the library supports
concurrency. The MT-Safe definition makes it
clear that the library is Safe, and supports some
concurrency. This clarifies the Safe definition,
which can mean anything from being single threaded
to being any degree of multithreaded.)
Now, what amount of concurrency is supposed to be supported by close(2)
that is Async-Signal-Safe? The ability to be closing more than one file
at a time using different threads? Perhaps.
So, with the jury still out, I'd advise you to consider these two
attributes orthogonal to be on the safe side.
Best regards.
Alexander
--
Dr Alexander Supalov
Senior Software Engineer
--------------------------------------------------------------------
//// pallas / A Member of the ExperTeam Group
Pallas GmbH / Hermuelheimer Str. 10 / 50321 Bruehl / Germany
Tel +49-2232-1896-34 / Fax +49-2232-1896-29
--------------------------------------------------------------------
1. Solaris 2.6: 'Async safe' implies 'thread safe' ?
Hi
I'm currently involved in multithreaded development tasks on
Solaris 2.6 and trying to make sense of the MT attributes for
system/library calls.
Especially, I'm wondering wether 'time' can be called safely
in a multithreaded app.
On the manpage of 'time' I read
____________________________________
| ATTRIBUTE TYPE| ATTRIBUTE VALUE |
|_______________|___________________|
| MT-Level | Async-Signal-Safe|
|_______________|___________________|
and for async-safety attributes(5) tells me
Async-Signal-Safe refers to particular library
routines that can be safely called from a signal
handler. A thread that is executing an Async-
Signal-Safe routine will not deadlock with
itself if interrupted by a signal. Signals are
only a problem for MT-Safe routines that acquire
locks.
Signals are disabled when locks are acquired in
Async-Signal-Safe routines. This prevents a
signal handler that might acquire the same lock
from being called.
Now, this description tells me that a thread calling
'time' won't deadlock in the call when interrupted
and that signals are disabled in 'time' whenever it
acquires locks.
It doesn't tell me wether any data can be corrupted
on reentering the call (i.e. is it 'Safe' ?) or wether
concurrency is provided (i.e. is it 'MT-Safe' ?).
Can anybody shed some light on this topic ?
Thanks a lot
Gunther
2. getpeername: Socket operation on non-socket
3. mmap, thread-safe, and signal-safe
4. Should I be dropping these?
5. Thread-safe and Signal-safe
7. Delivery of signals when thread not async safe
9. siglongjmp not async-signal-safe?
10. Why is localtime_r() not ASYNC-SIGNAL-safe ?
11. Threads in linux versus threads in NT and threads in Solaris.
12. localtime in Solaris 9 is not thread safe?
13. Threads in linux versus threads in NT and threads in Solaris.