C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 07-06-2009, 07:42 PM   #1
Registered User
 
Join Date: Jun 2009
Posts: 34
Using threads for control input (keyboard, serial)

I have a version of my app that is using threads to wait for keyboard input and input from the serial port (one thread for each). Based on what input is gathered from these threads, they set a variable in the calling thread so it knows what to do. Both threads are set up to loop infinitely and wait for keystrokes (thread1) or data coming in from the serial port (thread2).

The value they set in the calling thread's variable determines its course of action. The calling thread itself is in a loop (constantly reading this variable).

This seems to be working okay so far, but is there a better way to do this? I suppose I could put the checks for key and serial port input in the main loop, but what advantage would that offer? As I mentioned, the main loop just constantly checks a variable, so what does it matter whether it's set by its own loop or by some other thread?
synthetix is offline   Reply With Quote
Old 07-06-2009, 07:43 PM   #2
Senior software engineer
 
brewbuck's Avatar
 
Join Date: Mar 2007
Location: Portland, OR
Posts: 5,378
Threads seem like massive overkill. Use select().
__________________
"Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot
brewbuck is online now   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
About aes gumit C Programming 13 10-24-2006 03:42 PM
Catching All Keyboard Input nigma C Programming 6 06-11-2005 02:35 AM
Keyboard input in a Dialog ksarkar C++ Programming 1 05-20-2005 05:39 AM
getting input from keyboard, passing to execvp jumpyg C++ Programming 4 11-02-2003 08:49 PM
serial programming, threads and dynamic buffer lectrolux C Programming 1 05-06-2003 09:59 AM


All times are GMT -6. The time now is 05:55 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22