🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: ensuring CriticalSections are release..

#793
From: Bob Gonder
Date: Sun, 13 Jan 2008 23:43
27 lines
1857 bytes
Mike Collins wrote:

>I have a thread with a getter and setter to provide access to a private 
>variable.  I use a CRITICAL_SECTION to ensure thead-safety but i wasn't sure 
>about whether or not to use a try.. __finally to ensure that the CS always 
>gets released...

Why would you need a _finally?
Can the variable-access throw?

>try... __finally to ensure that a critical section is always released?

If so, how about a CS class of some sort?
(May be typing/logic/C++ errors)

ret_type Getter()
{	CS	cs(MyThreadCS);	// constructor enters critical section
	return	this.value;
}			// destructor releases critical section
	
class CS
{	LPCRITICAL_SECTION lpCriticalSection;
	CS(LPCRITICAL_SECTION CriticalSection)
		lpCriticalSection = CriticalSection
	{	EnterCriticalSection( lpCriticalSection ); }
	~CS(){	LeaveCriticalSection( lpCriticalSection ); }
}
Technical Details
Message-ID: <f77lo39kdtbbe7arsko6q5jlfko10li61c@4ax.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.germany.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <478a96e3@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,266d339b0fd4ba38
X-Google-Attributes: gid10cc67,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: Bob Gonder <notbg@notmindspring.invalid>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: ensuring CriticalSections are release..
Date: Sun, 13 Jan 2008 15:43:18 -0800
Organization: MindSpring Enterprises, Inc.
Reply-To: notbg@notmindspring.invalid
Message-ID: <f77lo39kdtbbe7arsko6q5jlfko10li61c@4ax.com>
References: <478a96e3@newsgroups.borland.com>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 67.77.145.88
X-Trace: newsgroups.borland.com 1200267794 67.77.145.88 (13 Jan 2008 15:43:14 -0700)
Lines: 28
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.germany.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail