[Prev][Next][Index][Thread]

Re: Pthreads and netio



> Date: Fri, 18 Jan 2002 11:10:44 -0800
> From: Titus Winters <twinters@odin.ac.hmc.edu>
> To: oskit-users@fast.cs.utah.edu
> Subject: Pthreads and netio
> 
> I notice that the documentation on pthreads states that it must be
> used very carefully, and that there is no oskit_wrap_netio to protect
> a netio object.  Does this indicate that using pthreads and low-level
> networking together is probably a bad idea?  
> 

There is actually an undocumented "thread aware" version of the netio.
(threads/netio.c).  The goal of this adaptor is to ensure that the push
function is invoked in a full pthread context.  This is an issue since
netio::push is typically invoked at interrupt time by the device driver
when a packet is received.  Special functions are:

oskit_netio_t *
oskit_threaded_netio_create(
    oskit_error_t (*func)(void *data, oskit_bufio_t *b, oskit_size_t pkt_size),
    void *data);

	Create a threaded netio.  The indicated function is called
	whenever a push is performed on the netio.

void
oskit_threaded_netio_run(oskit_netio_t *io);

	Turns the calling pthread into a service thread for the
	indicated netio.  Caller never returns, thus this thread
	must be explicitly destroyed (cancelled).

A "push" operation on a threaded_netio queues the bufio and wakes the
service thread.  When scheduled, that thread then dequeues the bufio
and invokes your create-time-specified "receive" function.  You can
send multiple pthreads into oskit_threaded_netio_run if you want to
multithread your receive function.