home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!munnari.oz.au!mel.dit.csiro.au!yarra!yarrina.connect.com.au!codex!bpja
- From: bpja@codex.com.au (Brett Adam)
- Newsgroups: comp.unix.programmer
- Subject: Re: Multithreads in SunOS 4.1.2
- Message-ID: <1992Sep11.085729.210@codex.oz.au>
- Date: 11 Sep 92 08:57:29 GMT
- References: <1992Sep10.114315.4875@knight.vf.ge.com>
- Sender: bpja@codex.oz.au
- Reply-To: bpja@codex.com.au
- Organization: Codex Software Development Pty Ltd
- Lines: 53
-
- In article <1992Sep10.114315.4875@knight.vf.ge.com> doug@happy.vf.ge.com (Doug
- Hughes) writes:
- > In article <1992Sep8.200022@hlrz24.hlrz.kfa-juelich.de>,
- melin@hlrz24.hlrz.kfa-juelich.de (Stephan Melin) writes:
- > > I have the following problem:
- > > I need to write a program that runs multiple processes concurrently, eg.:
- > >
- > > void proc(void);
- > >
- > > void main(void)
- > > {
- > > StartThread(proc);
- > > printf("main\n");
- > > ... /* some stuff to wait for the other thread */
- > > printf("main acknowledged\n");
- > > ... /* some stuff to tell the thread to go ahead */
- > > printf("end main\n");
- > > }
- > >
-
- [munch]
-
- > > Synchronization, of the processes will be done by semaphores...
- > > I have already looked at the lwp library, but I don't want to
- > > mess with this lowlevel stuff (I don't want to write my own
- > > scheduler). So is there any way to solve this problem in an
- > > easy way?
- > >
- > > Thanks in advance
- > >
- >
- > Why not just fork off a process and then exec a new process? That
- > way you can have the two processes running in parallel using the
- > existing UNIX scheduling algorithms. Then, all you have to write
- > is a good producer-consumer relationship (which can be pulled out
- > of any good OS textbook)
-
-
- Whilst this is valid, there are many cases where it is truly easier and better
- to use threads.
-
- What you want is the CMU cthreads library. It offers non-preemptive threading
- for Sun OS and many other platforms. Includes mutex variables, condition
- variables, etc. for thread sync and communications.
-
- I have the full source if you can't find it elsewhere.
-
- regards,
- --
- ---------------------------------------------------------------
- Brett Adam Xedoc Software Development Pty. Ltd.
- NeXTMail: bpja@codex.oz.au AppleLink: AUST0335
- (Preferred.) (Only if you must)
-