help-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re[2]: strage cthread behavior


From: Igor Shmukler
Subject: Re[2]: strage cthread behavior
Date: Mon, 01 Jul 2002 03:40:54 +0400

> > > libio is thread safe, though, and if he is usig a recent binary system
> > > (post ABI change), he will use libio and not stdio.
> > 
> > POSIX does not guarantee that printf is thread-safe
> 
> Why do you think so?  POSIX 1003.1 defines that all functions are
> thread-safe unless stated otherwise, and I couldn't find anything in the
> specification of printf that it isn't thread-safe.
> 
> > (although we are talking
> > cthreads which are not part of POSIX either) thus it is always is a good
idea
> > to not rely on printf being thread safe.
> 
> In any way, the GNU system makes this guarantee. 

Well,
Firstb of all, I want to say that you are correct. I did not explain myself
properly. Thanks for noticing that.
Yes, stdio calls are atomic. Thus you need not worry about syncing printfs.
However, this in way does guarantee that 
printf("Hello "); printf("World\n"); will in fact print Hello World.
POSIX provides the flockfile() and funlockfile() functions to address this, so
that you would instead use 
flockfile(stdout); 
printf("Hello "); printf("World\n");
funlockfile(stdout);
This will guarantee expected behaviour.
Otherwise stdout will could have whatever in it.

[OT] POSIX was designed so that people write portable soft, relying on GNU
systems features limits your options in terms of software usibility or/and
complicates development of portable code.
I am sure eventually GNU will switch to pthreads and other POSIX compliant
interfaces.

Sincerely,
IS.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]