🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: TCriticalSection between 2 threads

#2770
From: Eelke
Date: Tue, 28 Nov 2006 10:18
19 lines
1767 bytes
Tumurbaatar S. wrote:
> To communicate and pass data (several integers and AnsiString's) between 2 
> threads,
> I use TCriticalSection object. The first thread only writes/modifies the 
> protected section and
> the second one only reads. Of course, read/write operations are executed 
> within TCriticalSection's
> Enter/Leave(). My question: do I need to use Enter/Leave() if the writing 
> thread (the 1st one)
> needs to _read_ data that it modified? 
> 
> 
No you don't have to as problems can only arise when data is written 
while it is being read.

Actually for trivial data like a single integer no critical section is 
needed because the assignment of an int is an atomic operation.

Eelke
Technical Details
Message-ID: <456c0cd1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news1.google.com!news.maxwell.syr.edu!newsfeed.yul.equant.net!news-lond.gip.net!news.gsl.net!gip.net!colt.net!feeder.news-service.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <456bfb16@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,2ab3d3cded5b6fe1
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Tue, 28 Nov 2006 11:18:47 +0100
From: Eelke <e.klein@remove.mplussoftware.nl>
User-Agent: Thunderbird 1.5.0.8 (Windows/20061025)
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: TCriticalSection between 2 threads
References: <456bfb16@newsgroups.borland.com>
In-Reply-To: <456bfb16@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 195.241.133.37
Message-ID: <456c0cd1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1164709073 195.241.133.37 (28 Nov 2006 02:17:53 -0700)
Lines: 19
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news1.google.com!news.maxwell.syr.edu!newsfeed.yul.equant.net!news-lond.gip.net!news.gsl.net!gip.net!colt.net!feeder.news-service.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail