Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Threads

Author: Bruce Moreland

Date: 07:34:49 04/07/99

Go up one level in this thread



On April 07, 1999 at 01:29:30, James Robertson wrote:

>Just out of curiosity, how does a critical_section do this? Is it something
>built into Windows?

I don't know how they work.  I know that when you try to lock a critical section
it will efficiently wait if the critical section is busy, but that the whole
general concept is kind of expensive, meaning that it is not something you want
to be doing every node.

You can implement critical sections yourself via assembly code.  There are
instructions like "cmpxchg", and instruction prefixes like "lock".

If you are trying to control access to a fairly uncommon piece of code (a few
times per second), a critical section is great.  If you use the piece of code
more often than this, you still may have a hard time beating a critical section,
I think, but you might wish you could.

There are other primitives which are useful with threads.  You can create an
"event" object, and you can tell a thread to wait until the event is triggered.
While it's waiting it will sit there in an efficient state.

There are semaphores but I haven't had reason to use those yet.

Mutexes seem to be heavy-duty things that you'd use to keep different
*processes* from accessing a resource simultaneously.  That sounds pretty
expensive.

I don't know what I'm talking about, so if someone wants to correct me that
would be fine.

bruce



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.