开发者

Timer as a background job

开发者 https://www.devze.com 2023-02-13 09:24 出处:网络
I want to implement a timer so as to keep track of a test program. The timer will be in a different file and linked with my test.cc (test program).

I want to implement a timer so as to keep track of a test program. The timer will be in a different file and linked with my test.cc (test program).

I wantto keep track of execution, so as which statement takes how much time, and whe开发者_Python百科n the timer reaches certain interval may br 10 secs, i wish to do something, like may be aborting the test program.

I am using C++ in Linux environment. Can someone tell me how to achieve it?


There are several solutions possible.
If you can use POSIX threads and if the timer is only needed to end your application, then the "timer" can wait in a separate thread by using the nanosleep call. On wakeup, a signal can be sent (or a signal to a thread).

0

精彩评论

暂无评论...
验证码 换一张
取 消