I want to issue a command while another command is being executed in C++. For example wait command takes time for execution, and during this time I want to inject a different command and the wait command is completed.
well, there are at least 2 basic ways to do this.
1) instead of waiting, keep track of elapsed time and go run the other code while you wait on the time to reach the next mark to go back to whatever was 'waiting'. This is a type of scheduling, and suited for single threaded logic.
2) multi-threading. One thread can happily sleep while another works. With multi-core cpus, you can also do up to # of cores things at one time with threads.
it would be unwise to try to manually break a sleep command; I think that has OS level implications. A busy waiter loop can be broken of course, but that is just going to end up being some weird way to do #1 above.
double Timer::elapsedSeconds()
{
return elapsedMilliseconds() * 1000;
}
warning C4244: 'return': conversion from '_Rep' to 'double', possible loss of data
with
[
_Rep=__int64
]
I have used int and float as well in place of double.
When I use auto, error a function that returns 'auto' cannot be used before it is defined is generated.Any possible solutions. Thanks
if (timer.elapsedSeconds() > 90.0 && timer.elapsedSeconds() < 95.0)
{
ExecuteTMCRKPTRCommand("-----");
break;
}
}
//Stop Timer
timer.stop();
I want to insert this command ExecuteTMCRKPTRCommand("-----");in between when block of commands ExecuteTMCCODE("\\..........") are running. But it is not possible to stop the execution of ExecuteTMCCODE("\\..........") untill it is completed. So it is not possible to insert the command. Also I used timer outside the ExecuteTMCCODE("\\..........") without success. Any useful suggestions, please
idk. Should execute simultaneously. can't really make any guarantees tho how well it will actually work. Depending on how heavy the "command" is might need to create a new process to run it. *untested but i've used similar code in the past.