home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / unix / programm / 4631 < prev    next >
Encoding:
Internet Message Format  |  1992-09-11  |  2.3 KB

  1. Path: sparky!uunet!munnari.oz.au!mel.dit.csiro.au!yarra!yarrina.connect.com.au!codex!bpja
  2. From: bpja@codex.com.au (Brett Adam)
  3. Newsgroups: comp.unix.programmer
  4. Subject: Re: Multithreads in SunOS 4.1.2
  5. Message-ID: <1992Sep11.085729.210@codex.oz.au>
  6. Date: 11 Sep 92 08:57:29 GMT
  7. References: <1992Sep10.114315.4875@knight.vf.ge.com>
  8. Sender: bpja@codex.oz.au
  9. Reply-To: bpja@codex.com.au
  10. Organization: Codex Software Development Pty Ltd
  11. Lines: 53
  12.  
  13. In article <1992Sep10.114315.4875@knight.vf.ge.com> doug@happy.vf.ge.com (Doug  
  14. Hughes) writes:
  15. > In article <1992Sep8.200022@hlrz24.hlrz.kfa-juelich.de>,  
  16. melin@hlrz24.hlrz.kfa-juelich.de (Stephan Melin) writes:
  17. > > I have the following problem:
  18. > > I need to write a program that runs multiple processes concurrently, eg.:
  19. > > 
  20. > > void proc(void);
  21. > > 
  22. > > void main(void)
  23. > > {
  24. > >   StartThread(proc);
  25. > >   printf("main\n");
  26. > >   ... /* some stuff to wait for the other thread */
  27. > >   printf("main acknowledged\n");
  28. > >   ... /* some stuff to tell the thread to go ahead */
  29. > >   printf("end main\n");
  30. > > } 
  31. > > 
  32.  
  33. [munch]
  34.  
  35. > > Synchronization, of the processes will be done by semaphores...
  36. > > I have already looked at the lwp library, but I don't want to
  37. > > mess with this lowlevel stuff (I don't want to write my own
  38. > > scheduler). So is there any way to solve this problem in an
  39. > > easy way?
  40. > > 
  41. > > Thanks in advance
  42. > > 
  43. > Why not just fork off a process and then exec a new process? That
  44. > way you can have the two processes running in parallel using the
  45. > existing UNIX scheduling algorithms.  Then, all you have to write
  46. > is a good producer-consumer relationship (which can be pulled out
  47. > of any good OS textbook)
  48.  
  49.  
  50. Whilst this is valid, there are many cases where it is truly easier and better  
  51. to use threads.
  52.  
  53. What you want is the CMU cthreads library. It offers non-preemptive threading  
  54. for Sun OS and many other platforms. Includes mutex variables, condition  
  55. variables, etc. for thread sync and communications.
  56.  
  57. I have the full source if you can't find it elsewhere.
  58.  
  59. regards,
  60. -- 
  61. ---------------------------------------------------------------
  62. Brett Adam                 Xedoc Software Development Pty. Ltd.
  63. NeXTMail: bpja@codex.oz.au                  AppleLink: AUST0335
  64. (Preferred.)                                 (Only if you must) 
  65.