Article View: borland.public.cppbuilder.nativeapi
Article #7541Re: Accessing same variable from multiple threads
From: Ed Mulroy [TeamB]
Date: Wed, 19 Jan 2005 14:48
Date: Wed, 19 Jan 2005 14:48
31 lines
2140 bytes
2140 bytes
I am confused by the two critical sections. What am I missing?
I understand the idea is to block reading of a value that has been only
partially altered. Would it not work if a critical section were only
established for that code which modifies the variable?
. Ed
> Vladimir Afanasyev wrote in message
> news:41ee3727$1@newsgroups.borland.com...
>
> >There's a integer variable visible to 2 threads. One of the
> >threads reads/modifies this var, but other thread only
> >reads it. But an exact value of the var is not important
> >for the 2nd thread.
> >The thread checks it for zero or not, i.e. "if (my_var)...".
> >Is it not matter that I'm not using any synchronization
> >methods?
>
> If both threads from a single process you can use
> critical section objects for accessing to your variable.
> But in this case all access to variable must be in single
> critical section.
>
> EnterCriticalSection
> switch(threadNum)
> {
> case 1: {.... read variable.... } break;
> case 2: {.... read/modify variable ...} break;
> }
> LeaveCriticalSection
Technical Details
Message-ID:
<41ee742e$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!nx01.iad01.newshosting.com!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<41edea6b@newsgroups.borland.com> <41ee3727$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: "Ed Mulroy [TeamB]" <dont_email_me@bitbuc.ket> Newsgroups: borland.public.cppbuilder.nativeapi References: <41edea6b@newsgroups.borland.com> <41ee3727$1@newsgroups.borland.com> Subject: Re: Accessing same variable from multiple threads Date: Wed, 19 Jan 2005 09:48:09 -0500 Lines: 34 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 NNTP-Posting-Host: 24.211.226.180 Message-ID: <41ee742e$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1106146350 24.211.226.180 (19 Jan 2005 06:52:30 -0800) X-Authenticated-User: edmulroy Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshosting.com!nx01.iad01.newshosting.com!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail