Article View: borland.public.cppbuilder.nativeapi
Article #14327Re: TThreads & winapi critical section calls
From: Remy Lebeau (TeamB)
Date: Sat, 16 Aug 2003 03:11
Date: Sat, 16 Aug 2003 03:11
38 lines
2283 bytes
2283 bytes
"CC" <XXmailsink@aol.com> wrote in message
news:3f3d7670@newsgroups.borland.com...
> Does it sound resonable that one of these standard C
> library calls could not be playing nicely with multiple
> tthreads running at the same time?
Only if multiple threads were accessing the same file/socket without
synchronizing between them so that only 1 thread were accessing them at any
given time.
> int TMyThread::myFileOpen(.......)
> {
> int fd;
>
> EnterCriticalSection(&cs)
> fd = open(.....);
> LeaveCriticalSection(&cs)
> return fd;
>
> }
What exactly are you planning on doing with 'fd'? All you've done is
protect the initial opening the file. Unless you are calling
EnterCriticalSection() again, you are not going to be protecting the
modifying of the file as well. If you want to protect the file during the
entire transfer, you should be calling EnterCriticalSection() when you open
the file and LeaveCriticalSection() after you have closed it. Otherwise you
should rethink your design.
> Also the same for read/writing sockets, writing files,etc.
TServerSocket already performs locking operations internally to protect
itself.
Gambit
Technical Details
Message-ID:
<3f3d9f65$1@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!news.tele.dk!news.tele.dk!small.news.tele.dk!lnewspeer01.lnd.ops.eu.uu.net!emea.uu.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3f3d5dfa$1@newsgroups.borland.com> <3f3d64aa$2@newsgroups.borland.com> <3f3d7670@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 20:09:19 PST From: "Remy Lebeau \(TeamB\)" <gambit47@yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3f3d5dfa$1@newsgroups.borland.com> <3f3d64aa$2@newsgroups.borland.com> <3f3d7670@newsgroups.borland.com> Subject: Re: TThreads & winapi critical section calls Date: Fri, 15 Aug 2003 20:11:49 -0700 Lines: 40 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: <3f3d9f65$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1061003109 207.175.226.26 (15 Aug 2003 20:05:09 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!news.tele.dk!news.tele.dk!small.news.tele.dk!lnewspeer01.lnd.ops.eu.uu.net!emea.uu.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail