Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Threads

Author: Peter McKenzie

Date: 18:51:41 04/06/99

Go up one level in this thread


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.

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.