🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: TThread w/standard open(),close(),etc

#14336
From: Dennis Jones
Date: Sun, 17 Aug 2003 04:24
39 lines
2956 bytes
"CC" <Xcurtc@tmscorp.com> wrote in message
news:3f3d5a5b$1@newsgroups.borland.com...
> Greetings All.
> I have a TThread'ed program that uses open() close() access() and other
> standard C library calls within the TThread object.
>
> I was wondering if anyone knows if doing this is thread safe with the
> standard library functions? Not sure how the winapi under neath implements
> these functions.

In general, standard library calls are thread-safe, unless they are known to
be non-reentrant.  A function such as strtok() is not thread-safe because it
not reentrant; that is, it uses a static local variable internally to
maintain state between calls, and that variable would easily get clobbered
by each thread that calls it.  In such a case, you would have to write your
own thread-safe version, or find one elsewhere.

Where you run into trouble with threads in the standard library is not
typically with the calls themselves, but with the resources accessed by
those calls.  For instance, if you use open() to get a file handle and then
try to read() and write() that same file handle simultaneously in separate
threads, you are going to have problems, because you will not have control
over which thread is doing what at any given time.  And as you are no doubt
already aware (based on your other post), the role of the synchronization
primitives is to prevent the simultaneous access of those resources.

Of course, this also implies that if you are accessing a different resource
in each thread, there is (usually) no problem, because the threads are not
competing for access to the same resource.

Does this help?

I'm curious...you are obviously not writing code that needs to be
cross-platform compatible (based on your use of TThread), so why are you
using the standard C calls open/close, rather than the Win32 calls,
FileOpen/FileClose?

- Dennis
Technical Details
Message-ID: <3f3f0397$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-09!supernews.com!newsfeed.news2me.com!elnk-nf2-pas!elnk-pas-nf1!newsfeed.earthlink.net!border3.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <3f3d5a5b$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,6d5349d41523236b
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-08-16 21:30:09 PST
From: "Dennis Jones" <djones@nospam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3f3d5a5b$1@newsgroups.borland.com>
Subject: Re: TThread w/standard open(),close(),etc
Date: Sat, 16 Aug 2003 21:24:56 -0700
Lines: 41
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: 204.200.27.7
Message-ID: <3f3f0397$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1061094295 204.200.27.7 (16 Aug 2003 21:24:55 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-09!supernews.com!newsfeed.news2me.com!elnk-nf2-pas!elnk-pas-nf1!newsfeed.earthlink.net!border3.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail