Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Multithreading question

Author: Bo Persson

Date: 02:17:29 09/09/03

Go up one level in this thread


On September 09, 2003 at 04:10:53, Tony Werten wrote:

>On September 09, 2003 at 03:21:34, Andreas Herrmann wrote:
>
>>On September 09, 2003 at 02:14:08, Tony Werten wrote:
>>
>>Hi Tony,
>>
>>i have just read inside a Delphi internals book last week a 50 side long capitel
>>about Thread programming. It says that all local vars are save, but pay
>>attention for global vars. See the help to the win api function
>>EnterCriticalSection or the VCL object TCriticalSection as a good starting point
>>to this theme.
>>
>>Andreas
>
>Thanks ( to all)
>
>It seems that "write" is not threadsafe when used for writing to the console.

"write" is never thread safe, as it surely uses some global variables to
remember the console state.

>I
>added some checks to make sure only 1 thread is writing at a time. Hope this
>solves the problems.

Another way to do this is to have one thread responsible for all the I/O, and
have other "worker threads" do the chess stuff. This way you don't have to lock
the console.

>
>The problems became worse when I changed from writeln to write which seems
>logic: more time spend in writing so bigger change for collisions.

I guess writeln empties the global line buffer each time it is called. Write
might collect more data before actually writing to the console. If it is called
from several threads at once, it is sure to get garbled.

>
>
>Tony
>

Bo Persson



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.