problems with stdout

Hi,

I am checking different functionalities of NTO through several C
programs. Usually I use printf within threads to prove for concurrency
and verify the sincronitzation operations between them.

Some times I get no output from printf so I am forced to include fflush
after each printf. Should I conclude that for reliability I should use
always the pair printf-fflush?
This sounds hightly unconvinient for me!

Moreover, from time to time, when working with fflush I get duplicated
output. Even more unconvinient! Why happens this?

Since using stdout seems so unreliable, what would be the recommended
method to
trace concurrency and other functionalities. I know about the
instrumented microkernel but I would like something simplier. Maybe
outputting messages to a file?

Any answer or suggestion will be appreciated.

Thanks,

Ramon

In article <3CF4A2FF.D7071A0D@esaii.upc.es>, Ramon Sarrate wrote:

Some times I get no output from printf so I am forced to include fflush
after each printf. Should I conclude that for reliability I should use
always the pair printf-fflush?
This sounds hightly unconvinient for me!

stdout is a buffered stream. That means that it is flushed when the
buffer becomes full and/or when you print an \n (usually).

To implicitly flush stdout is it sufficient to print a \n at the end of
the string. Better of all, instead, use stderr which isn’t buffered.

Hope this helps.


Wave++ (Yuri D’Elia)
Software Developer @ ubiest.com

Yuri D’Elia <wavexx@hydra.ubiest.com> wrote:

In article <> 3CF4A2FF.D7071A0D@esaii.upc.es> >, Ramon Sarrate wrote:
Some times I get no output from printf so I am forced to include fflush
after each printf. Should I conclude that for reliability I should use
always the pair printf-fflush?
This sounds hightly unconvinient for me!

stdout is a buffered stream. That means that it is flushed when the
buffer becomes full and/or when you print an \n (usually).

To implicitly flush stdout is it sufficient to print a \n at the end of
the string. Better of all, instead, use stderr which isn’t buffered.

It may also be worth taking a look at setvbuf(). It describes the
three types of buffering supported by the library.

IOFBUF – fully buffered, don’t write output until buffer is full.
stdout defaults to this if writing to a file
IOLBUF – line buffered, write output if buffer is full or newline (\n)
character is encountered. stdout defaults to this for a terminal
IONBUF – no buffering, write output immediately, stderr defaults to this

fflush() will force a flush (write) of output on a buffered stream.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

Thank you Yuri and David for your suggestions.

I have solved those problems.

Ramon

David Gibbs wrote:

Yuri D’Elia <> wavexx@hydra.ubiest.com> > wrote:
In article <> 3CF4A2FF.D7071A0D@esaii.upc.es> >, Ramon Sarrate wrote:
Some times I get no output from printf so I am forced to include fflush
after each printf. Should I conclude that for reliability I should use
always the pair printf-fflush?
This sounds hightly unconvinient for me!

stdout is a buffered stream. That means that it is flushed when the
buffer becomes full and/or when you print an \n (usually).

To implicitly flush stdout is it sufficient to print a \n at the end of
the string. Better of all, instead, use stderr which isn’t buffered.

It may also be worth taking a look at setvbuf(). It describes the
three types of buffering supported by the library.

IOFBUF – fully buffered, don’t write output until buffer is full.
stdout defaults to this if writing to a file
IOLBUF – line buffered, write output if buffer is full or newline (\n)
character is encountered. stdout defaults to this for a terminal
IONBUF – no buffering, write output immediately, stderr defaults to this

fflush() will force a flush (write) of output on a buffered stream.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.