On (18 Oct 97) Andrew Seddon wrote to All...
AS> Hi. I was wondering if anybody could tell me where I can get an
AS> example of a multithreaded protocal, if possible source code in C++.
AS> By multithreaded I mean a protocal that will allow me to send and
AS> recive multiple packets at once.
What sort of protocol did you have in mind? Modem? Network? IPC?
Something else?
It's also a bit uncertain exactly what you mean by "send and receive
multiple packets at once." Do you mean being able to invoke the
function to send or receive a packet before a previous call has
necessarily completed? Do you mean being able to specify more than one
packet in a single call to the function? Do you mean the ability for
the driver to simultanously receive one packet while it's sending a
different packet?
Simply allowing multiple calls to be made while transactions are taking
place is relatively simple. In fact, most systems that support
multi-threading to start with will handle this more or less
automatically for things like serial ports and network connections.
About all that's involved is a queue in the driver. When you make a
call to send or receive a packet, it simply gets queued up. Then the
driver itself simply grabs requests out of the queue, and carries them
out in order.
Depending upon exactly what behavior is desired, the driver might
alternatively simply have a mutex semahphore that allows only one thread
to access the actual hardware at a time. When one request completes,
one of the threads that has made a request is awakened and allowed to
carry out its request.
The first of these creates a non-blocking call, so a single thread can
queue up multiple requests on the same resource. The second is a
blocking call that simply protects the resource so if multiple threads
of execution attempt to access it at once, their access will happen
serially rather than one munging up communications by another.
Later,
Jerry.
--- PPoint 2.02
---------------
* Origin: Point Pointedly Pointless (1:128/166.5)
|