Article View: borland.public.cppbuilder.nativeapi
Article #7557Re: Accessing same variable from multiple threads
From: Vladimir Afanasyev
Date: Wed, 19 Jan 2005 19:07
Date: Wed, 19 Jan 2005 19:07
40 lines
2909 bytes
2909 bytes
>If there are _any_ threads that modify the variable, then all threads
>must cooperate to ensure that it is only modified when none are also
>trying to read it.
Exactly.
>
>Otherwise, the writing thread may have partially updated it when a
>reading thread attempts to read it. If it's a primitive, and you only
>have a single processor machine with no ability to actually execute more
>than one thread at a time, then I don't think you will see thread
>switching in the middle of the write.
>
>However, some of us already have multi-processor PCs, and also
>hyperthreading and multi-core CPUs will be increasingly common in the
>near future. With these, I think even a primitive is no longer safe.
>
If the question what reading thread will see ("variable before"
or "variable after") it is not important. Windows is not
"real-time" system and beside this dispatch threads (even for
multi processor) in the way that Microsoft guys know only.
Really if another threads will work in system (it is normally
thing) that will do some another work it will be absolutely
impossible when and what value reading thread MUST read -
value before changing or after.
For example, thread must read value in 10:00 but just before
this time dispatcher pass control to another thread. So
variable was read in 10:00:00.20 but another thread made
changes in 10:00:00.10. If first thread read it in time
(10:00:00.00) it read before value but in above case it
read after value. The critical section can't help in this case.
But if value can change during some period of time... Oh, in this case
reading thread may listen or watch all its time carefully (via continuos
enters in critical section or semaphor) for changing.
Vladimir.
Technical Details
Message-ID:
<41eeaff9$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!newsfeed2.dallas1.level3.net!news.level3.com!news-out.visi.com!spool-3.news.visi.com!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<41edea6b@newsgroups.borland.com> <41ee3727$1@newsgroups.borland.com> <41ee742e$1@newsgroups.borland.com> <41ee8f57$1@newsgroups.borland.com> <qu9tu0hgv4gqnlvv65nqq70ua4v73jv0mu@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: "Vladimir Afanasyev" <avv@systema.kiev.ua> Sender: "Vladimir Afanasyev" <avv@systema.kiev.ua> Reply-To: "Vladimir Afanasyev" <avv@systema.kiev.ua> Subject: Re: Accessing same variable from multiple threads Newsgroups: borland.public.cppbuilder.nativeapi X-User-Info: 83.218.237.46 X-Forwarded-For: unknown References: <41edea6b@newsgroups.borland.com> <41ee3727$1@newsgroups.borland.com> <41ee742e$1@newsgroups.borland.com> <41ee8f57$1@newsgroups.borland.com> <qu9tu0hgv4gqnlvv65nqq70ua4v73jv0mu@4ax.com> NNTP-Posting-Host: 207.105.83.66 Message-ID: <41eeaff9$1@newsgroups.borland.com> Date: 19 Jan 2005 11:07:37 -0800 X-Trace: newsgroups.borland.com 1106161657 207.105.83.66 (19 Jan 2005 11:07:37 -0800) Lines: 40 Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!newsfeed2.dallas1.level3.net!news.level3.com!news-out.visi.com!spool-3.news.visi.com!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail