[comp.os.mach] Interrupting a msg_receive from another thread

epstein@trwacs.UUCP (Jeremy Epstein) (04/02/91)

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.

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()?

Thanks for any suggestions!
--Jeremy
-- 
Jeremy Epstein			UUCP: uunet!trwacs!epstein
Trusted X Research Group	Internet: epstein@trwacs.fp.trw.com
TRW Systems Division		Voice: +1 703/876-8776
Fairfax Virginia

Richard.Draves@cs.cmu.edu (04/02/91)

> 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