gpt4 book ai didi

c - 如何用C语言创建一个定时器?

转载 作者:行者123 更新时间:2023-11-30 15:26:48 24 4
gpt4 key购买 nike

我想创建一个计时器来计算秒数并显示它们,但同时我想做其他操作。有人可以解释一下我该怎么做或者这是否可能(在 Visual Studio 中)?

最佳答案

This is one way to handle your desired actions.

in main thread,
-fork a child process. passing
1) a desired time interval
2) a callback function ptr
3) indication of oneShot or repeating timer
into the child process,

in the child process:
-begin loop
-sleep the passed-in-time-interval
-execute the call back function
-if non repeating timer
-then
-exit child process
-endif
-end loop

in main thread, in the call back function:
-get current time
-display the current time to user
-return

in main thread, when ready to exit, kill child thread

关于c - 如何用C语言创建一个定时器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27285336/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com