🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Synchronized call

#4773
From: Alistair
Date: Wed, 30 Nov 2005 23:33
39 lines
1807 bytes
Bogdan wrote:
> Hello,
> 
> How can I synchronize a function call from a thread using API functions.
> I need to do what Synchronize(Function) from TThread does, but
> with Win 32 API.
> 
> Thanks
> Bogdan 
> 
>

// SECTION OBJECT
CRITICAL_SECTION _section;

// CREATES THE SECTION
// ONLY DO THIS ONCE BEFORE ALL THE THREADS GO ACTIVE
InitializeCriticalSection(&_section);

// FUNCTION USED BY MANY THREADS
void DoSomethingThatNeedsSync()
{
  // THIS WILL WAIT!
  EnterCriticalSection(&CriticalSection);
// OR - THIS WILL NOT WAIT
//TryEnterCriticalSection(CriticalSection);

  // MANY THREADS DO THIS!

  LeaveCriticalSection(&CriticalSection);
}

// DELETE CRITICAL SECTION
// ONLY DO THIS AFTER ALL THE THREADS ARE FINISHED
DeleteCriticalSection(&CriticalSection);


Cheers,
Alistair
Technical Details
Message-ID: <438e3682@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <438e1a53@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,38c7fb08131702ad
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Wed, 30 Nov 2005 23:33:01 +0000
From: Alistair <NoSpamPlease@Somewhere.Com>
User-Agent: Thunderbird 1.4 (Windows/20050908)
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: Synchronized call
References: <438e1a53@newsgroups.borland.com>
In-Reply-To: <438e1a53@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 84.9.168.65
Message-ID: <438e3682@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1133393538 84.9.168.65 (30 Nov 2005 15:32:18 -0700)
Lines: 39
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail