Article View: borland.public.cppbuilder.nativeapi
Article #14370Re: TThreads & winapi critical section calls
From: CC
Date: Mon, 18 Aug 2003 18:45
Date: Mon, 18 Aug 2003 18:45
64 lines
3079 bytes
3079 bytes
Hi Remy-
The thread does standard C library open(),close(),access(),read(),write()
calls only on file descriptors that it opened (for files), and send(),recv()
calls only on the socket descriptor it was passed. (The reason for using
standard libary calls is that I'm using code portable with unix)
From previous post I'm starting to think that my usage of file calls may not
be problem when used in a thread, since all data accessed passed to these
functions is internal to the TThread.
Should send() and recv() be thread safe also? I couldn't imagine them not
being.
You assistance it much appreciated.
CurtC
"Remy Lebeau (TeamB)" <gambit47@yahoo.com> wrote in message
news:3f3d9f65$1@newsgroups.borland.com...
>
> "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:
<3f411eb3$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!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> <3f3d9f65$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-18 12:12:07 PST From: "CC" <Xcurtc@tmscorp.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3f3d5dfa$1@newsgroups.borland.com> <3f3d64aa$2@newsgroups.borland.com> <3f3d7670@newsgroups.borland.com> <3f3d9f65$1@newsgroups.borland.com> Subject: Re: TThreads & winapi critical section calls Date: Mon, 18 Aug 2003 13:45:47 -0500 Lines: 66 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.1165 NNTP-Posting-Host: 208.254.250.201 Message-ID: <3f411eb3$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1061232307 208.254.250.201 (18 Aug 2003 11:45:07 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail