home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / os / os2 / programm / 7112 < prev    next >
Encoding:
Text File  |  1992-12-18  |  2.4 KB  |  64 lines

  1. Newsgroups: comp.os.os2.programmer
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!malgudi.oar.net!news.ans.net!cmcl2!panix!os2man
  3. From: os2man@panix.com (Larry Salomon Jr.)
  4. Subject: Re: OS/2 libraries thread-safe ?
  5. Message-ID: <1992Dec17.183135.16800@panix.com>
  6. Date: Thu, 17 Dec 1992 18:31:35 GMT
  7. References: <1992Dec16.221352.26031@cs.tu-berlin.de> <1992Dec17.094108.12612@eua.ericsson.se>
  8. Organization: PANIX Public Access Unix, NYC
  9. Lines: 53
  10.  
  11. In <1992Dec17.094108.12612@eua.ericsson.se> etxabju@eua.ericsson.se (Anders Bjurman) writes:
  12.  
  13. >In article 26031@cs.tu-berlin.de, ernst@opal.cs.tu-berlin.de (Ernst Kloecker) writes:
  14. >>Hi,
  15. >>
  16. >>what precautions do I have to take when calling C-library functions from
  17. >>different threads in one process ?
  18.  
  19. >There are (at least) two versions of the library - one "normal" and one thread safe.
  20. >In MSC you invoke the thread safe library with -MT.
  21.  
  22. In C Set/2, you use the -Gm+ switch.
  23.  
  24. >>What happens to static variables like 'errno' ?
  25.  
  26. >No problem. errno is redefined with the preprocessor to a thread-safe function:
  27. >#define errno thread_safe_errno_function() or something like that.
  28.  
  29. Same with C Set/2.
  30.  
  31. >>Can I safely call '...printf()' from different threads ?
  32.  
  33. >Not quite sure, but I think so. printf/sprintf etc uses (in MSC) a static result
  34. >array. This array is guarded with semaphores. However, there can be a small risk
  35. >that the output from several threads are mixed with each other (but only one
  36. >of them calls printf() of course).
  37.  
  38. Yes, you can safely call any runtime function from separate threads, as long
  39. as you link with the proper library (or let the compiler generate the "default
  40. library object records" so that the linker knows).
  41.  
  42. >>Or are the only safe functions the OS-functions in 'bsedos.h' ?
  43.  
  44. >Sorry.
  45.  
  46. All of the OS/2 API are thread safe; it would be stupid for them not to be
  47. since this is, after all, a multi-threading OS.
  48.  
  49. >>Or are even those functions not completely thread-safe ?
  50. >>
  51. >Not absolutly sure how they are implemented, but functions like strtok(),
  52. >localtime(), gmtime() etc seems a bit dangerous - I guard them with a semaphore
  53. >when I use them.
  54.  
  55. I think he was referring to the system API.  Again, both the C Set/2 and
  56. system API are thread-safe.
  57.  
  58. Cheers,
  59. Q
  60. -- 
  61. "If you choose not to decide, you  | "My other body is in the shop" - seen
  62.  still have made a choice" - Rush  |  on a T-shirt
  63. ------------------------------------------------------------------------
  64.