Fedora Linux Support Community & Resources Center
  #1  
Old 21st September 2005, 10:50 AM
Stevenisme Offline
Registered User
 
Join Date: Nov 2004
Posts: 454
Program c++ problem.

Hi all,
I would like to ask a question about C++.
If I have

....
void checkInput(); //this will ask the user to input something
void print(); //print out something .i.e just a action
int main(){
......
checkInput();
print();
....


In the above code if the user not input anyting. the program will hesitate( waiting )
So how can C++ can run serveral things( several function) at the same time?
for example.
listen music and use the xterm ( just as FC )
is that several programs are run one by one not at the same time?
first open mp3-player( run in the background ) then run xterm
__________________
You whom I have upheld since you were conceived, and have carried since your birth. Even to your old age and gray hairs I am he, I am he who will sustain you. I have made you and I will carry you; I will sustain you and I will rescue you.
(Isaiah 46:3-4)
Reply With Quote
  #2  
Old 21st September 2005, 11:56 AM
Shakes Offline
Registered User
 
Join Date: Feb 2005
Location: Scotland
Posts: 445
They are seperate processes. Since it's compiled to machine code, the operating system is just switching between which code is running, to give concurrent but seperate processes. If one process is waiting it does not affect the code of another process
Reply With Quote
  #3  
Old 21st September 2005, 01:06 PM
Stevenisme Offline
Registered User
 
Join Date: Nov 2004
Posts: 454
Thx Shakes,
How about my example that if the user do not input something the print() will not run.
so if the checkInput() function not finished. the code will not go to print().
if inside the checkInput(). I have done this:
int i;
cout << "Input some integer\n";
cin >> i;
...
the print() will be excuate until finished the checkInput().
If so.
I want to continue to remind someone to input something in my checkInput().( may be add a loop here)
But the code will stop at "cin >> i".......
What I want to know is that how can C++ run several functions at the same time.
eg
reminder(); //continute to remaind you to do something til the program end
showTime(); //display the current time
input(); //continue to input something to a file

PS:
I am runing at console only.
__________________
You whom I have upheld since you were conceived, and have carried since your birth. Even to your old age and gray hairs I am he, I am he who will sustain you. I have made you and I will carry you; I will sustain you and I will rescue you.
(Isaiah 46:3-4)
Reply With Quote
  #4  
Old 21st September 2005, 01:32 PM
Shakes Offline
Registered User
 
Join Date: Feb 2005
Location: Scotland
Posts: 445
If you want to run code simultaneously, then you will have to use threads. Threads are similar to processes but share memory and can be in the same application. Google should provide more details, I would suggest "C++ threads".
Reply With Quote
  #5  
Old 21st September 2005, 02:32 PM
tashirosgt Offline
Registered User
 
Join Date: Aug 2004
Posts: 3,964
You might be able to take the input with a non-blocking read(). See
man 2 open
and look at O_NONBLOCK
Or do as Shakes suggested, do
man pthread_create
__________________
"Never let the task you are trying to accomplish distract you from the study of computers."
Reply With Quote
  #6  
Old 21st September 2005, 03:00 PM
Stevenisme Offline
Registered User
 
Join Date: Nov 2004
Posts: 454
I see, thx I must read this first
__________________
You whom I have upheld since you were conceived, and have carried since your birth. Even to your old age and gray hairs I am he, I am he who will sustain you. I have made you and I will carry you; I will sustain you and I will rescue you.
(Isaiah 46:3-4)
Reply With Quote
Reply

Tags
problem, program

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem getting a program to run at startup Elite Racing Using Fedora 3 26th April 2009 09:29 AM
Problem with program! chilavert1 Using Fedora 11 27th February 2009 12:21 PM
kde program crash problem tgbzsq Using Fedora 31 3rd April 2008 07:53 AM
problem in program type barq Using Fedora 2 5th February 2008 09:02 PM
problem installing program jenny_psion Using Fedora 2 22nd June 2006 05:09 PM


Current GMT-time: 18:32 (Thursday, 23-10-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat
Yeola - Vettur - Gyumri Instagram Photos