hi I'm new to boost.threads and have a basic question. During program execution the user has to check the connection to a server. This action should take place in a simple thread. If the user gets bored waiting for responce, he should be able to stop the process and return back to the main application. Is there a proper standard solution? For now I try to yield the thread holding the connection methods. In this case the inner methods all terminate and are not going to be stopped. My first attemp is to stop this inner methods by hand. Is there a better way to do this? kind regards, luke
Hi, anyone know of necessary additions and tweaks to the emacs c++-mode so that it will help format C++ template code in the same style that can be found in the book "C++ Template Metaprogramming"? -- Best Regards, Fredrik Hedman
lukas wrote:
hi
I'm new to boost.threads and have a basic question. During program execution the user has to check the connection to a server. This action should take place in a simple thread.
Do you mean that the program attempts to make a socket connection using a new thread?
If the user gets bored waiting for responce, he should be able to stop the process and return back to the main application.
How will the user interrupt?
Is there a proper standard solution?
A common approach in POSIX would be to use non-blocking sockets and to use the select() function to wait for a change of state on the socket(s) or on standard input (or, in an X application, on the pipe or socket used by Xlib). This way, there is no need to spawn a new thread per connection (though it is useful to have another thread for doing name lookups, because there is no standard API for running them asynchronously). Under Windows you would probably use MsgWaitForMultipleObjects() or asynchronous socket operations. I'm afraid Boost.Thread doesn't cover these things, though asio http://asio.sourceforge.net/ and Giallo http://giallo.sourceforge.net/ attempt to. Ben.
On Tue, 2005-10-04 at 16:00 +0100, Ben Hutchings wrote:
I'm new to boost.threads and have a basic question. During program execution the user has to check the connection to a server. This action should take place in a simple thread.
Do you mean that the program attempts to make a socket connection using a new thread?
If the user gets bored waiting for responce, he should be able to stop the process and return back to the main application.
How will the user interrupt?
You could also define a volatile bool, which the thread checks once in x steps ( i could imagine this thread being in some sort of loop ). If this bool changes value, perhaps by another thread which is in control of a user interace, the thread could cease all actions and exit. The both threads would have to share one common value, though... -- Leon Mergen
participants (4)
-
Ben Hutchings
-
Fredrik Hedman
-
Leon Mergen
-
lukas