[prev in list] [next in list] [prev in thread] [next in thread] 

List:       hurd-help
Subject:    Re[2]: strage cthread behavior
From:       "Igor Shmukler" <shmukler () mail ! ru>
Date:       2002-06-30 23:40:54
[Download RAW message or body]

> > > 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.



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic