Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!udel!rochester!pt.cs.cmu.edu!o.gp.cs.cmu.edu!andrew.cmu.edu!+ From: Richard.Draves@cs.cmu.edu Newsgroups: comp.os.mach Subject: Re: Interrupting a msg_receive from another thread Message-ID: <4bxs0Cu00hsQ5UaWR0@cs.cmu.edu> Date: 1 Apr 91 18:46:38 GMT References: <283@trwacs.UUCP> Organization: Carnegie Mellon, Pittsburgh, PA Lines: 44 In-Reply-To: <283@trwacs.UUCP> > Excerpts from netnews.comp.os.mach: 1-Apr-91 Interrupting a msg_receive > .. Jeremy Epstein@trwacs.UU (1672) > Environment: Running Mach 2.5 on a Sun 3, using the cthreads library. > I've got a server with three threads. Clients send this server > receive rights on two ports, one for normal messages and one for > critical messages. > In the server, one thread (call it A) sits and builds up a port set (by > collecting receive rights for the normal messages), and also selects one > of the critical ports to be the focus port. The second thread (thread B) > reads messages from the port set consisting of all of the normal ports. > The third thread (thread C) reads from the current focus port only. > There are two problems here: First, the port set may increase (new ports > may be added by thread A) while thread B is doing a msg_receive()). > Second, thread A may choose a different focus port while thread C is > doing a msg_receive(). > In the first case, I can overcome the problem by periodically waking > up from the msg_receive (i.e., use a timeout) and select the port set > again [or will the port_set_add() in thread A automatically cause the > msg_receive in thread C to see messages which arrive on the new port?] > In the worst case, I'd wait a big longer than I need before I receive > a message from the new port. This isn't too serious. Thread B does not have to restart its msg_receive to see the effects of port set membership changes. > However, in the second case I could receive a message from a port which > is no longer the focus port. This turns out to be undesirable. > The question [finally!]: Is there any reasonable way for thread A to > wake thread C from its msg_receive()? The easiest way to wake a thread from a msg_receive is to send the thread a message. You could also put the critical ports into a port set, except for the focus port from which thread C receives. To change focus ports, thread A takes the new focus port out of the port set and adds the old focus port to the port set. This will wake C with an error, because you can't receive directly from a port in a port set. Rich