🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #7575

Re: Accessing same variable from multiple threads

#7575
From: Remy Lebeau (TeamB)
Date: Thu, 20 Jan 2005 17:52
41 lines
2931 bytes
"Alan Bellingham" <alanb@episys.com> wrote in message
news:qmmtu09mtj1dnckicq85cq03k9ro6aqsje@4ax.com...

> Nope - because as Gambit points out, your primitive may require
> more than one access to read or write. At least on the x86
> architecture, which doesn't insist on DWORDs being DWORD aligned.
>
> In such a case, it ain't atomic any more.

Correct.  If a value is not aligned properly, it may take multiple
read/write operations to access the value.

> My point was that I didn't think the scheduler would interrupt
> during the read or the write.

It can for misaligned values.

> But I'm not sure how low it goes, and whether it will interrupt
> during what is apparently a single CPU operation.

Atomic operations cannot be interrupted.  There is no way they could be.
The scheduler needs CPU cycles to perform its work, just like any other
task, but the CPU performs one operation at a time and atomic operations use
a single CPU cycle.

> However, if I remember my assembler, there are some instructions that
> go on for a potential lifetime by CPU clock cycle standards, so maybe
> it does.

Some instructions do take up multiple CPU cycles, and as such can be
preempted by the scheduler.  That is why task switching preserves all
current register values during the switch.  When the scheduler switche back,
the preempted operation can pick up where it left off and it never knows
that it was interrupted.  The problem occurs when operations are accessing
non-stack memory, which can be altered when the tasks switched around.  The
preempted operation has now way of knowing that the memory it was accessing
had been altered while the operation was suspended.


Gambit
Technical Details
Message-ID: <41efef51$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshosting.com!nx02.iad01.newshosting.com!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <41edea6b@newsgroups.borland.com> <41ee3727$1@newsgroups.borland.com> <41ee742e$1@newsgroups.borland.com> <41ee8f57$1@newsgroups.borland.com> <qu9tu0hgv4gqnlvv65nqq70ua4v73jv0mu@4ax.com> <ktatu01v81kub73v28uhkhp1ccrl4ct9j6@4ax.com> <qmmtu09mtj1dnckicq85cq03k9ro6aqsje@4ax.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,4809cdd9a7828fa7
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <41edea6b@newsgroups.borland.com> <41ee3727$1@newsgroups.borland.com> <41ee742e$1@newsgroups.borland.com> <41ee8f57$1@newsgroups.borland.com> <qu9tu0hgv4gqnlvv65nqq70ua4v73jv0mu@4ax.com> <ktatu01v81kub73v28uhkhp1ccrl4ct9j6@4ax.com> <qmmtu09mtj1dnckicq85cq03k9ro6aqsje@4ax.com>
Subject: Re: Accessing same variable from multiple threads
Date: Thu, 20 Jan 2005 09:52:34 -0800
Lines: 43
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.69.17.41
Message-ID: <41efef51$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1106243409 68.69.17.41 (20 Jan 2005 09:50:09 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshosting.com!nx02.iad01.newshosting.com!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail