473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

terminate thread waiting on cin

I'm using Boost to run a couple of threads, one of which reads commands
via std::cin and another receives them through a socket. It's entirely
possible that during the life of the app, all commands will be sent
through the socket and the thread watching cin will never "see any
action". So the problem is, how do I terminate this thread that waits
for keyboard input?

Unfortunately, Boost::thread doesn't yet allow me to force the thread
to terminate. Even after I exit main(), the app doesn't die until
something is entered via cin. I'm trying to keep the code
cross-platform compatilible so I'd like to avoid any OS-specific
gobledigook.

Any ideas?

Thanks in advance!

Jan 9 '06 #1
3 5939
Are you sure Boost::thread does have nothing similar to
pthread_cancel() ?

This is the posix way to cancel threads, even the system-call blocked
ones

Jan 9 '06 #2
Mr Dyl wrote:
I'm using Boost to run a couple of threads, one of which reads commands
via std::cin and another receives them through a socket. It's entirely
possible that during the life of the app, all commands will be sent
through the socket and the thread watching cin will never "see any
action". So the problem is, how do I terminate this thread that waits
for keyboard input?

Unfortunately, Boost::thread doesn't yet allow me to force the thread
to terminate. Even after I exit main(), the app doesn't die until
something is entered via cin. I'm trying to keep the code
cross-platform compatilible so I'd like to avoid any OS-specific
gobledigook.

Any ideas?
Nothing definitive. Terminating a thread is generally an extremely bad
idea. You could close the file handle/file descriptor of cin/STDIN, and
it should stop the read. But that's OS specific.

Assuming just one thread can use cin, why not run the ui in the main thread?
Thanks in advance!

Jan 9 '06 #3
Yeah, I know killing the thread with brute force isn't a good idea
which is why I was hoping there'd be an elegant solution.
Unfortunately Boost doesn't have any equivalent to pthread_cancel() as
Diego was asking (although the hint that it is forthcoming).

I don't want cin in my main thread because the main thread has to be
able to respond to input from other sources (sockets and files).
Basically there are 3 ways to control the main thread, of which cin is
just one.

It's looking like I'm going to have to hack this somehow :(

Jan 11 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Gilles Leblanc | last post by:
Hi I have started a small project with PyOpenGL. I am wondering what are the options for a GUI. So far I checked PyUI but it has some problems with 3d rendering outside the Windows platform. I...
11
by: Bob Rock | last post by:
Hello, coming from win32 API I recall an ExitThread() call to gently terminate a thread from inside the same thread .... but now all I can see is an Abort call which seems to me a wrapper on the...
9
by: liangbowen | last post by:
As i konw, the only way to to terminate a thread started by _beginthread() is to user _endthread() (or return) inside the thread. now i started a thread(TodoThread), and created a listenning...
4
by: Dr. J | last post by:
How to terminate a blocked thread? In my form's "load" I launch a TCP listening thread that stays in an infinite loop waiting for incoming TCP packets. In this form's "closing" I try to...
5
by: | last post by:
Hi I have thread that recives event notifications from a server. the thread is created as a managed thread. But when using Thread Abort the thread doesn't terminate. the thread is in an...
3
by: Kathy Burke | last post by:
Hi, I'm tired, so this question may be silly. I have a fairly long sub procedure. Based on one condition, I load another sub with the following: If Session("GRN") = "complete" Then txtScan.Text...
2
by: R. Nachtsturm | last post by:
Hi, i have the problem that when i create a low priority background thread, start it, and wait for it to finish that it does not seem to terminate even after it is finished.. if i use...
2
by: Bob | last post by:
I launch Word from within my application (Vs2005, VB) and I would like to make it necessary for the just opened Word to be closed before the rest of my code in the calling sub can execute. How can...
3
by: Gary Wessle | last post by:
#include <boost/thread/thread.hpp> #include <iostream> using namespace std; class waiter { public: waiter(); void waiting(); void preform();
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.