1

I want to realize a timeout function in C++ on a Atmel evaluation kit.

The program should open the function "start()" and if this function is not completed within "0.5s" it should be killed.

Are there any existing function to do jobs like this?

regard matl

4
  • try using sleep in callee and after sleep return to caller Commented Mar 24, 2014 at 12:28
  • look at std::async and std::chrono Commented Mar 24, 2014 at 12:50
  • 1
    @AliKazmi: sleep function requires an operating system. Embedded systems may not have an OS. Commented Mar 24, 2014 at 13:14
  • @OMGtechy std:chrono give me the timeperiode of a function, but if it is hanging in the function because of for example big calculations or an error I am not able to kill the function because I will get the result too late. Commented Mar 24, 2014 at 23:09

2 Answers 2

1

Yes: std::future::wait_for. You get either future_status::ready or future_status::timeout.

Sign up to request clarification or add additional context in comments.

2 Comments

This is possible only in C++11 (-std=c++11 or -std=c++0x depending on compiler). On C++03 you have to use OS calls (if one) or implement it via interrupt
@elvis.dukaj: Of course. But the question wasn't tagged C++03 or C++14, so the reasonable assumption is C++ as it's defined today.
1

In my experience, these kinds of functions are always hand-crafted because in embedded systems, the target system is not standardized.

You could purchase an OS and use methods like messaging timeouts and sleeping.

Without an OS, you have to craft the functionality yourself using a timer and the timer interrupt (ISR).

2 Comments

Are there any suggetions how to create a timeout with timer and timer interrupt? At the moment I do not know how to realize something like this. If the program is hanging in the function start() how can I access the timer data? Maybe it is just a error in reasoning but I do not get it now.
@matl It's very specific to the hw. You have to refer to the libraries given with the enviorment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.