gpt4 book ai didi

c - 注册一个新的线程处理程序,如 pthread_atfork 或 atexit

转载 作者:太空宇宙 更新时间:2023-11-04 10:47:07 25 4
gpt4 key购买 nike

我有一个监视器/(看门狗类线程)线程,用于查询所有线程的性能统计信息。来自/proc/self/tasks 的thread 的thread 查询列表 一旦创建了列表,我不想再读取/proc/self/tasks 除非新线程创建或旧线程退出。其他线程不知道此线程,因此它们无法创建 pthread_key 以在退出时获得回调,或者它们无法在生成时在线程队列中添加新条目。

我正在为线程寻找 pthread_atfork 或 atexit 等 api。

最佳答案

I am looking for api like atfork/pthread_atfork [...] for threads.

没有。

您需要自己为此设置簿记。


编写一个包装器线程函数,传递给每次调用 pthread_create() 并让它设置 cleanup-pusher/-popper-stuff。作为 pthread_create() 的参数,您传递一个指向“真实”线程函数的指针,然后在包装器“调用”pthread_cleanup_push() 之后调用该函数。

关于c - 注册一个新的线程处理程序,如 pthread_atfork 或 atexit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32680016/

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