In a message dated 4/19/2001 12:03:25 AM Eastern Daylight Time,
[EMAIL PROTECTED] writes:
> From: Peter Harper <[EMAIL PROTECTED]>
> Subject: ns_cond, threads and file descriptors.
>
> I've been trying to find a solution to the following problem...
>
> I have two message queues in shared memory, one for incoming messages, one
> for outgoing. I have a thread that gets kicked off for processing the
> incoming messages as they appear on the queue. This thread waits for a
> particular event, which is signalled by another thread (see below) as it
> populates the incoming message queue.
>
> The outgoing message queue is populated by *any* thread through shared
> memory
> access.
>
> A second thread is started that opens and reads/writes to a local device
> (using standard file IO). So any messages appearing on the outgoing message
> queue are written, and anything from the device added to the incoming queue.
>
> My problem is that I'd like to use an ns_cond/ns_event to inform this second
> thread that messages are available to be written to the device. But I also
> want to use a fileevent callback to read data off the device when its
> available and populate the incoming message queue. As far as I can tell,
> there is no clean way to achieve both these things, and I'm c
Hi,
In general, the way to mix file events with thread events is via a trigger
pipe and select(), i.e., instead of a blocking read/write on an fd, you
select on the fd plus the read side of a pipe. To wakeup the waiting thread,
send a byte down the pipe. This technique is used in the Tcl 8 event code as
well as the nssock driver, the keepalive thread, and the socket callback
interface. That may be a way to do what you're after although it may be
hard to get to work in Tcl instead of C.
-Jim