Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何解决带参函数的定时 #2

Open
xiangTo opened this issue Oct 22, 2019 · 2 comments
Open

如何解决带参函数的定时 #2

xiangTo opened this issue Oct 22, 2019 · 2 comments

Comments

@xiangTo
Copy link

xiangTo commented Oct 22, 2019

这个软定时器个人觉得很不错啊,但是带参函数的定时似乎没法做到,有办法解决吗

@xiangTo
Copy link
Author

xiangTo commented Oct 22, 2019

目前我的解决办法是定义全局变量标志位,然后定时器做置位操作;然后在while循环里轮询标志位,通过标志位判断来定时调用带参函数。

@flyiingdust
Copy link

目前我的解决办法是定义全局变量标志位,然后定时器做置位操作;然后在while循环里轮询标志位,通过标志位判断来定时调用带参函数。

可以将回调函数形参修改为(void *arg),在初始化timer是将所需传递数据放入,回调触发时进行数据转换,以此实现参数传递。这个实现参考自线程pthread_create函数中对于不定类型参数的传递处理。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants