473,387 Members | 1,464 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,387 software developers and data experts.

Threads hangs and won't accept any user input

Program should accept user input and do appropriate actions. But program hangs after creating 60 threads, that is after 60 transaction even if user submits input it doesn't take. I read that TerminateThread has some memory problems but couldn't find alternate solutions to fix this.

I highly appreciate some help. I am using VC++ and following code build and executes fine.
Expand|Select|Wrap|Line Numbers
  1. #include <iostream.h>
  2. #include <windows.h>
  3.  
  4. #define DEFAULT 9
  5. int enterMsg;
  6. int incr=0;
  7.  
  8. //Thread function to take user input 
  9. void UserOptionFunc()
  10. {
  11.     cout << "\n\n\t" << ++incr << " If you want to enter message type 1 else 0 : " ;
  12.     cin >> enterMsg;
  13. }
  14.  
  15. void main()
  16. {
  17.         /* elapsed times in microseconds */
  18.         unsigned long counter;    
  19.  
  20.         DWORD threadID;
  21.         HANDLE hThread;
  22.  
  23.         while(1){
  24.             enterMsg = DEFAULT;
  25.             counter  = 0;
  26.  
  27.             hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)UserOptionFunc, 0, 0, &threadID);
  28.  
  29.             while(counter < 500000000){
  30.                 counter++ ;
  31.             }
  32.             if(enterMsg != DEFAULT){
  33.                 cout << "USER ENTERED: " << enterMsg << endl;
  34.             }
  35.  
  36.             TerminateThread(hThread, 0);
  37.         }
  38. }
Aug 3 '08 #1
1 1632
weaknessforcats
9,208 Expert Mod 8TB
The first thing to do is check hThread for zero after the CreateThread call to be sure you are getting a thread handle.
Aug 3 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: anuradha.k.r | last post by:
hi, i am writing a socket program in python,both client side and server side.I've written the client side which is working perfectly fine(checked it against server program written in C).but as for...
5
by: Bart Nessux | last post by:
Could someone explain the concept of threads and how I might use them in Python? I was a math major, not a CS major (theory instead of practice). Most of my programming knowledge has grown out of...
6
by: sathyashrayan | last post by:
Following are the selected thread from the date:30-jan-2005 to 31-jan-2005. I did not use any name because of the subject is important. You can get the original thread by typing the subject...
6
by: RahimAsif | last post by:
Hi guys, I would like some advice on thread programming using C#. I am writing an application that communicates with a panel over ethernet, collects data and writes it to a file. The way the...
1
by: opi | last post by:
My blocking TCP server hangs in the Accept method when the client software sometimes gets an error. Are there any ways to stop this blocking in the Accept method so I dont have to restart the...
2
by: reizes | last post by:
I am having a problem with python threads and M2Crypto. It appears the M2Crypto used in multi-thread application blocks other threads from running: Environment: Linux 2.6 (centos 5.0), OpenSSL...
5
by: Saya | last post by:
Hi Folks, I have now spend app. 3 days to get the below scenario to work, but can not get there! ..Net version = 2.0.50727 Windows version = Microsoft Windows = Windows Server 2003 Now I...
7
by: Brendon Costa | last post by:
Hi all, I have a small python project i am working on. Basically i always have two threads. A "Read" thread that sits in a loop reading a line at a time from some input (Usually stdin) and then...
0
by: cbeels | last post by:
The client code is #install SOAP-Lite and MIME-tools packages use SOAP::Lite 'trace', 'debug'; #override version SOAP::Lite->soapversion('1.2'); #override credentials sub...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.