Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: multithreading question (OT)

Author: Eugene Nalimov

Date: 09:32:54 03/02/01

Go up one level in this thread


On March 02, 2001 at 10:03:58, Pat King wrote:

>On March 02, 2001 at 08:45:51, Robert Hyatt wrote:
>
>>On March 02, 2001 at 08:39:57, Pat King wrote:
>>
>>>if sizeof(somebuiltintype) <= sizeof(sig_atomic_t), is it garunteed that reads
>>>and writes of somebuiltintype are atomic?
>>>
>>>thanks.
>>>
>>>Pat
>>
>>
>>I don't think it matters.  You _first_ use an atomic operation to lock the
>>data in question, then you don't have to worry about whether the read/write
>>is atomic.  IE my hash entries are 16 bytes so that would probably never be
>>an atomic read/write.
>
>But if the data in question is very simple (as in this case setting a bool flag
>or two) then a lock seems overkill. certainly almost any struct wouldn't be, but
>what of a bool or a char? For instance, my compiler (mingw) has sig_atomic_t as
>a typedef int, 4 bytes. so is anything 4 bytes or smaller atomic?

On x86, no. Your data can be unaligned (absolutely valid on any x86 OS I know
of), cross the page boundary, and one of the pages can be swapped out. Then
you'll get the OS call in the middle of the memory write.

Eugene



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.