Boost logo

Boost :

From: Markus Schöpflin (markus.schoepflin_at_[hidden])
Date: 2002-11-25 10:05:47


Hu Xinwei wrote:

>> - How to interupt a thread waiting on some socket event
>> (synchronous and asynchronous) from another thread?
>
> IMHO, I dont think such a mechanism is needed.

A typical example: You have a thread that implements a synchronous
listener like this:

bind();
listen();

while (true)
{
   fd = accept();
   // add fd to some connection list
}

It is surprisingly difficult to portably tell this thread that it
should terminat itself.

>> - How do you wait for more than just socket events? Thread
>> conditions, window messages, ...
>
> I think that is not a problem too. We at such a condition, should
> have 2 threads, one to block on socket, and another handles all
> other messages from os, other processes...... If you are really
> intersted in the thread conditions, you have to poll them by
> yourself, because there is no such a generic mechanism on every
> platform

And that's one of the main reasons why we should provide one. At least
a possible interaction with conditions from boost threads.

> and it is rearly used.

What makes you think so? It's quite important in server programming.

> IMO, thread model is used to simplify your design. One thread
> should take one resposibility and one only.

Say you have a thread responsible for communication with some clients.
You have to have a way to tell this thread that there is new data
available for the client. At the same time the thread has to wait for
new data coming in from the client. How do you solve this?

Markus


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk