Article View: comp.os.os2.programmer
Article #2905Re: OS/2 libraries thread-safe ?
From: Anders Bjurman
Date: Thu, 17 Dec 1992 09:41
Date: Thu, 17 Dec 1992 09:41
49 lines
2438 bytes
2438 bytes
In article 26031@cs.tu-berlin.de, ernst@opal.cs.tu-berlin.de (Ernst Kloecker) writes:
>Hi,
>
>what precautions do I have to take when calling C-library functions from
>different threads in one process ?
>
What C library? I can only speek for Microsoft C 6.0. I not quite sure about IBM Cset/2
yet, but I think the answers are applicable for that library as well.
There are (at least) two versions of the library - one "normal" and one thread safe.
In MSC you invoke the thread safe library with -MT.
>What happens to static variables like 'errno' ?
No problem. errno is redefined with the preprocessor to a thread-safe function:
#define errno thread_safe_errno_function() or something like that.
>
>Can I safely call '...printf()' from different threads ?
Not quite sure, but I think so. printf/sprintf etc uses (in MSC) a static result
array. This array is guarded with semaphores. However, there can be a small risk
that the output from several threads are mixed with each other (but only one
of them calls printf() of course).
>
>Or are the only safe functions the OS-functions in 'bsedos.h' ?
Sorry.
>Or are even those functions not completely thread-safe ?
>
Not absolutly sure how they are implemented, but functions like strtok(),
localtime(), gmtime() etc seems a bit dangerous - I guard them with a semaphore
when I use them.
>
>Thanks for any info, Ernst.
>--
No problem. Hope it helped. Can someone with experience from Cset/2 and emx
tell how it's done there?
---
__________________________________________________________
`"""' _/ RF Anders Bjurman, Memo: eri.etx.etxabju \_
O O __/ Ericsson Telecom AB Anders.Bjurman@eua.ericsson.se \
> _/ S-125 25 Alvsjo, Sweden +46 8 727 49 80 _/
o \_______________________________________________________________/
Technical Details
Message-ID:
<1992Dec17.094108.12612@eua.ericsson.se>Path:
arc1-ca.pugleaf.net!sparky!uunet!mcsun!sunic!ericom!eua.ericsson.se!euas67c28!etxabjuReferences:
<1992Dec16.221352.26031@cs.tu-berlin.de>Show Full Headers
Complete Article Headers
Newsgroups: comp.os.os2.programmer Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!sunic!ericom!eua.ericsson.se!euas67c28!etxabju From: etxabju@eua.ericsson.se (Anders Bjurman) Subject: Re: OS/2 libraries thread-safe ? Message-ID: <1992Dec17.094108.12612@eua.ericsson.se> Sender: news@eua.ericsson.se Nntp-Posting-Host: euas67c28.eua.ericsson.se Reply-To: etxabju@eua.ericsson.se Organization: Ellemtel Telecom Systems Labs, Stockholm, Sweden References: <1992Dec16.221352.26031@cs.tu-berlin.de> Date: Thu, 17 Dec 1992 09:41:08 GMT Lines: 51