Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!samsung!uunet!sbi!zeus!bpa_su10!sivan From: sivan@bpa_su10.Sbi.Com (Sivan Mahadevan) Newsgroups: comp.windows.x Subject: Re: signals using XLib Message-ID: <120@bpa_su56.bpa_su10.Sbi.Com> Date: 18 Dec 90 14:29:47 GMT References: <1990Dec17.134238.26720@nas.nasa.gov> Organization: BPA - Salomon Brothers, NY Lines: 41 In article <1990Dec17.134238.26720@nas.nasa.gov>, parlette@nas.nasa.gov (Edward B. Parlette) writes: > I am writing a program using straight XLib and need to be able > to break out of the Event loop if I haven't received a keypress > event within a certain amount of time. I have used alarm calls > in the past for this and am wondering if this will cause a problem > with XLib calls ?? I thought I saw a message on the new that claimed > using signals with X was a bad idea but I have forgotten why. > kelvin email: kelvin@calvin.larc.nasa.gov > calvin.larc.nasa.gov In order to make use of signals in the manner you wish, you need to 1) Build a version of Xlib that is signal re-entrant 2) Take special precautions on the type of X calls made from within signal handlers. Xlib comes with LockDisplay and UnlockDisplay macros, #define'd to be empty. If you set macros these to block and unblock signals respectively (using sigblock() and sigsetmask()), then you have an Xlib that is re-entrant for a given signal. However, if you just do this, then you won't be able to catch any signals when waiting in the event loop (i.e., in XNextEvent()). Therefore, make sure you remove the LockDisplay and UnlockDisplay macros from XNextEvent(). You have to be careful to not do any "event management" within signal handlers, because with the above Xlib, XNextEvent() itself is not re-entrant. Therefore don't call any X*Event() routines from within signal handlers and don't call XSync() or XFlush() either. The best practice is to do as little X in the signal handlers as possible, and wait until you get back to main loop to do the work. -- Sivan Mahadevan Salomon Brothers Inc Bond Portfolio Analysis Analytical Applications Group One New York Plaza 44th Floor 212-747-5418 New York NY 10004 sivan@bpa_su10.sbi.com uunet!sbi.com!bpa_su10!sivan