Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

writeln thread safe ?

308 views
Skip to first unread message

Skybuck Flying

unread,
Mar 1, 2003, 2:30:04 PM3/1/03
to
Hi,

I just wrote a console application which starts 4 threads.

each threads writes text to the console with writeln.

It seems to work fine...

Yet I am not sure if this is 100% thread safe ?

Any comments ?

--
http://www.mycgiserver.com/~skybuck
http://skybuck.soshost.net


Skybuck Flying

unread,
Mar 1, 2003, 3:45:34 PM3/1/03
to
probably not...

I just tested some app on a slow p166.. it looked like it managled some
text.

procedure my_writeln( s : string );
begin
critical section.enter;

writeln( s );

critical section.leave;

end;

would probably solve it if one really cares :)

"Skybuck Flying" <nos...@hotmail.com> wrote in message
news:b3r1na$r7f$1...@news2.tilbu1.nb.home.nl...

Robert Cerny

unread,
Mar 4, 2003, 2:32:37 PM3/4/03
to
Only if each thread writes its own text device.
Since all write to console, you have to use a CriticalSection.

--
Robert Cerny


"Skybuck Flying" <nos...@hotmail.com> wrote in message
news:b3r1na$r7f$1...@news2.tilbu1.nb.home.nl...

Skybuck Flying

unread,
Mar 6, 2003, 9:31:58 AM3/6/03
to
"Robert Cerny" <robert.q...@neosys.xrs.qwe.si> wrote in message
news:b432h5...@neosys.xrs.si...

> Only if each thread writes its own text device.
> Since all write to console, you have to use a CriticalSection.

Multiple text devices ? Can you give a example of such a program ?


Robert Cerny

unread,
Mar 6, 2003, 10:25:13 AM3/6/03
to
Read delphi help about "Text-file device drivers".
Text device can access text files, console, com port, printer,....
writeln('blabla') //writes to standard output
writeln(Prn,'blabla') //writes to printer

--
Robert Cerny


"Skybuck Flying" <nos...@hotmail.com> wrote in message

news:b47m4d$b48$1...@news4.tilbu1.nb.home.nl...

Mikael Mann

unread,
Mar 6, 2003, 8:21:49 PM3/6/03
to

WriteLn() copies the string to the Delphi device buffer, adds a LnFeed,
then flushes the buffer using WriteFile(). In rare cases, thread congestion
may occur so that you get merged strings with double linefeeds etc.

For proper console output, make your own wrappers for GetStdHandle() and
WriteFile(). (Hey, you can even implement your own
ScrollConsoleScreenBuffer() wrapper for fun!)

My all-in-all conclusion after nn years of Borland-loyalty is that Delphi
is a NICE language with its language and compiler, but the RTL kinda sucks.
Look at the various WinSock and ISAPI libraries. It makes me wanna puke.


- M.m.

Skybuck Flying

unread,
Mar 6, 2003, 9:01:34 PM3/6/03
to
"Mikael Mann" <n...@mail.com> wrote in message
news:3e67f42c$1...@news.wineasy.se...

>
> WriteLn() copies the string to the Delphi device buffer, adds a LnFeed,
> then flushes the buffer using WriteFile(). In rare cases, thread
congestion
> may occur so that you get merged strings with double linefeeds etc.
>
> For proper console output, make your own wrappers for GetStdHandle() and
> WriteFile(). (Hey, you can even implement your own
> ScrollConsoleScreenBuffer() wrapper for fun!)

Neh... I rather see borland implement turbo vision for delphi :D

> My all-in-all conclusion after nn years of Borland-loyalty is that Delphi
> is a NICE language with its language and compiler, but the RTL kinda
sucks.
> Look at the various WinSock and ISAPI libraries. It makes me wanna puke.

?

0 new messages