Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Threads

Author: Peter McKenzie

Date: 01:42:21 04/07/99

Go up one level in this thread


On April 07, 1999 at 01:52:06, James Robertson wrote:

>On April 06, 1999 at 21:51:41, Peter McKenzie wrote:
>
>>On April 06, 1999 at 21:30:34, James Robertson wrote:
>>
>>>I am thinking of making my program multithreaded to ease implementation of
>>>several things. But before I begin, I have several questions: first, if I have
>>>an input thread that just sits with cin, and my search thread is doing stuff in
>>>the background, will the search thread be slowed? Second, about locking and
>>
>>No, it won't be significantly slowed if you are doing blocked input (something
>>like 'cin >> str;'.  You'd worry more if you are polling, but you can easily put
>>a call to Sleep into your polling loop.
>>
>>>unlocking resources shared between threads; how is this usually done? If I just
>>>declare a variable, say
>>>
>>>bool locked = false;
>>>
>>>Can I "lock" and "unlock" resources by just:
>>>
>>>....
>>>
>>>//see if the variable is locked
>>>if (!locked) {
>>
>>one thread might get to here, then have to yield time, meaning that the other
>>thread could get to here too...
>>
>>>  locked = true;
>>>  //change shared resources
>>>  locked = false;
>>>}
>>>
>>>Will this work?
>>
>>most of the time :-)
>>
>>>
>>>Any help is appreciated.
>>
>>For a start, look at the Win32 (assuming your're using windows) documentation on
>> critical sections.
>
>Just out of curiosity, how would one port WIn32 stuff to, say, Unix or some
>other system?

I think Unix has a similar set of synchronisation pimitives to Win32.
Java has good support for threading built into it.
I think you can also write your own locking code with aid of some assembler (see
Crafty code).

>
>James
>
>>
>>cheers,
>>Peter
>>
>>>James
>>>
>>>....



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.