Home > Back-end >  C on a question of time
C on a question of time

Time:04-23

Everyone a great god, and how to set the c + + program stop execution after n seconds (a piece of code it is best to stop it, continue to below)

CodePudding user response:

And this demand?
If it is the language is quite good, using coroutines and channel (channel) to control the
C + +, can use a child process and wait for the process to do
Or try to achieve a similar function of go, refer to the following link
https://blog.csdn.net/eclipser1987/article/details/24324955

CodePudding user response:

for(int i=0; iWhere N the pause time is longer, the greater the but it is difficult to precisely how many seconds to stop,

CodePudding user response:

Windows SuspendThread; Hung thread

CodePudding user response:

reference 1st floor qybao response:
and this demand?
If it is the language is quite good, using coroutines and channel (channel) to control the
C + +, can use a child process and wait for the process to do
Or try to achieve a similar function of go, refer to the following link
https://blog.csdn.net/eclipser1987/article/details/24324955

Sorry! I know I this demand is a bit sharp cry] [a smile, but still thanks for your help, if not too can didn't also way,

CodePudding user response:

reference GKatHere reply: 3/f
Windows SuspendThread; Hung thread
excuse me, can say detailed point

CodePudding user response:

Your code to be executed on the thread, directly hung thread when to stop

CodePudding user response:

refer to 6th floor Italink response:
your code to be executed on the thread, to stop directly hung thread
I'm sorry, I'm beginner c + +, really do not understand, can you do a small piece of sample

CodePudding user response:

references at the end of the 7th floor filmmaker 014 response:
Quote: refer to the sixth floor Italink response:

Your code to be executed on the thread, to stop directly hung thread
I'm sorry, I'm beginner c + +, really do not understand, what can you do a short sample
with Sleep function, Sleep (1000) on behalf of 1000 milliseconds

CodePudding user response:

In the clock interrupt program counter, when the count reaches a certain time, skip this code, don't know whether you want is the result?

Func ()
{
Code A

if(! (count> N))
Code section B

Code C

}

CodePudding user response:

Beginners will play a multithreaded?

CodePudding user response:

Trigger, and with thread waits for a task, set the timeout, more than sleep

CodePudding user response:

Wait for a condition have been false

CodePudding user response:

T1=gettime () + n "s
While (gettime
//to continue

CodePudding user response:

T1=gettime () + n "s
While (gettime{
Task...
}

//the end of the program

CodePudding user response:

You can use a count variable to record programs use long.
If the count is greater than or equal to a number, you will exit the program.

CodePudding user response:

Or you can to write a program to make the program in the background Sleep for a while, and then it's time for direct use system () can be shut down the program
I think it is more simple...
  • Related