🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: TThreads & winapi critical section calls

#14321
From: Remy Lebeau (TeamB)
Date: Fri, 15 Aug 2003 23:01
55 lines
2487 bytes
"CC" <Xcurtc@tmscorp.com> wrote in message
news:3f3d5dfa$1@newsgroups.borland.com...

> I was wondering if within a TTHread,
> is it ok to use the winapi:
>   EnterCriticalSection();
>   LeaveCriticalSection();
>   InitializeCriticalSection();
>
> Calls?

Of course.  TThread simply wraps an API thread object.  Critical Sections
are designed to be used with threads, particularly with multiple threads
accessing them at the same time.

> I have a tthread program, which I suspect is having
> problems somewhere with multiple threads running
> non-thread safe code.

Always a source of potential problems.

> I wanted to do something like:
> EnterCriticalSection(...);
> // read a file here, read from socket, close file, etc
> LeaveCriticalSection();

That is perfectly fine.

> I would imaging the synchronize uses these calls.

Only in BCB6.  In BB1-5, it does not use any API synchronization objects at
all.  It uses its own custom mechanism utilizing window messages instead.

> The problems w/synchronize you cant pass arguments, etc to sync. function.

That is only partially true.  Although you cannot pass any parameters when
calling Synchronize() itself, you can store the desired values into separate
variables which the synched method can then use once it is executed, ie:

    AnsiString MyStr = "whatever";
    int MyInt = 50;

    ...
    Synchronize(SomeMethod);
    ...

    void __fastcall TMyThread::SomeMethod()
    {
        // use MyStr and MyInt as needed
    }



Gambit
Technical Details
Message-ID: <3f3d64aa$2@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!newsfeed.online.be!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <3f3d5dfa$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,455292b256c8f5c8
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-08-15 16:09:15 PST
From: "Remy Lebeau \(TeamB\)" <gambit47@yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3f3d5dfa$1@newsgroups.borland.com>
Subject: Re: TThreads & winapi critical section calls
Date: Fri, 15 Aug 2003 16:01:13 -0700
Lines: 57
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 207.175.226.26
Message-ID: <3f3d64aa$2@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1060988074 207.175.226.26 (15 Aug 2003 15:54:34 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!newsfeed.online.be!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail