🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Accessing same variable from multiple threads

#7546
From: Remy Lebeau (TeamB)
Date: Wed, 19 Jan 2005 17:43
29 lines
2304 bytes
"Vladimir Afanasyev" <avv@systema.kiev.ua> wrote in message
news:41ee8f57$1@newsgroups.borland.com...

> If both threads works asynchronously - one modifies when want,
> another reads when want then no need any critical sections and
> semaphors for both threads.

They do need to share a common instance of the critical section or semaphor,
and they both need to use it in order to properly protect the shared data in
a synchronized manner.  Without it, one thread could be reading the data at
the exact same moment that another thread is altering the data.

> As I understand critical section do not block access to
> sharing variable. Only code inside critical section is blocked.

True.  But if all access to the shared variable is done from inside a
critical section, then all access is effectively serialized so that only one
thread can get to the variable at a time.

> Really no need to use it when one thread modify and another
> only read (it can be useful only if some threads make modifications).

Yes, you do need to use it in that situation.  If you do not, then when the
one thread alters the data, the reading thread may get the wrong value, or
worse, get a corrupted value since the data is still being written to.


Gambit
Technical Details
Message-ID: <41ee9bd1$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!proxad.net!194.117.148.138.MISMATCH!pe2.news.blueyonder.co.uk!blueyonder!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>

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>
Subject: Re: Accessing same variable from multiple threads
Date: Wed, 19 Jan 2005 09:43:51 -0800
Lines: 31
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: <41ee9bd1$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1106156497 68.69.17.41 (19 Jan 2005 09:41:37 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!proxad.net!194.117.148.138.MISMATCH!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail