home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!know!hri.com!noc.near.net!news.Brown.EDU!qt.cs.utexas.edu!cs.utexas.edu!sun-barr!ames!purdue!mentor.cc.purdue.edu!noose.ecn.purdue.edu!ecn.purdue.edu!kudva
- From: kudva@ecn.purdue.edu (Gautham K. Kudva)
- Newsgroups: comp.unix.programmer
- Subject: SUMMARY: Signal Handlers and malloc()
- Message-ID: <1992Nov13.041318.15609@noose.ecn.purdue.edu>
- Date: 13 Nov 92 04:13:18 GMT
- Sender: news@noose.ecn.purdue.edu (USENET news)
- Followup-To: comp.unix.programmer
- Organization: Purdue University Engineering Computer Network
- Lines: 47
-
- Hi,
- A few days ago I had posted in this group requesting some
- help with signal handlers. My problem was that I was calling malloc
- from within a signal handler, and when the signal handler was invoked
- while control was within a malloc call, the function had to be re-entered.
- Since malloc is not designed to be re-entrant, this trashed the program.
- I asked if there were any re-entrant versions of routines like malloc() or
- routines that guarded the calls by blocking signals. Thanks to the following
- people for their help:
-
- Rob Sartin
- Mitchell Perilstein
- Russell Spence
- Rob Quinn
- Christoph Badura
- Steve McPolin
- Mark Lawrence
-
- Everyone who responded to my post informed me that I should
- not attempt such stuff from within signal handlers. The suggestion was
- that I should restructure my code so that signal handlers would just set
- some flags, and the application loop should do work based on these flags.
-
- Unfortunately, this is not possible for my program, since what
- I was really trying to achieve using signals was a crude form of threads.
- I am trying to write a distributed application on a workstation network.
- My program has a computation thread (which will include third party
- code such as Linear Programming solvers) and a communication thread
- to enable a number of these programs to talk over a network. The
- communication thread acts not only as an interface to the particular
- program, but also as a routing point for messages between other processes.
- So it is imperative that the communication thread be invoked at regular
- intervals. I cannot depend on the computation thread to co-operate, since
- it includes third party code that won't necessarily yield control to the
- communication thread periodically.
-
- Something like pthreads or cthreads would have been ideal for my
- situation. However I haven't been able to find a single package that will run
- on a mix of Sun SPARCs, HP-7000s and RS-6000s. I thought I might be
- able to get the same effect using singals but guess not! For the time being
- I have decided to restrict myself to LWP on Suns and hope that pthreads
- will be available on all platforms sometime in the future (with Solaris on
- Suns and OSF/1 on HPs and IBMs)
-
- Once again thanks to everyone who responded
- Gautham
- kudva@ecn.purdue.edu
-