简体   繁体   English

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

[英]Register a new thread handlers like pthread_atfork or atexit

I have a monitor/(watchdog kind of thread) thread which is used for query perf statistics of all threads. 我有一个Monitor /(看门狗类线程)线程,用于所有线程的查询性能统计。 The thread query list of thread from /proc/self/tasks Once the list is created, I don't want to read /proc/self/tasks again unless new thread created or old thread exited. 来自/ proc / self / tasks的线程的线程查询列表创建列表之后,除非重新创建新线程或退出旧线程,否则我不想再次读取/ proc / self / tasks。 Other thread are not aware of this threads so they can't create pthread_key to get callback on exit or they can't add new entry in thread-queue on spawning. 其他线程不知道该线程,因此它们无法创建pthread_key来在退出时获取回调,或者无法在生成时在线程队列中添加新条目。

I am looking for api like pthread_atfork or atexit for threads. 我在寻找像pthread_atfork或atexit这样的线程API。

I am looking for api like atfork/pthread_atfork [...] for threads. 我正在寻找像atfork / pthread_atfork [...]这样的api作为线程。

There is none. 空无一人。

You need to setup book-keeping for this yourself. 您需要为此自己设置簿记。


Write a wrapper thread function which is passed to each call of pthread_create() and have it set up the cleanup-pusher/-popper-stuff. 编写一个包装器线程函数,该函数将传递给每个pthread_create()调用,并设置cleanup-pusher / -popper-stuff。 As an argument to pthread_create() you pass a pointer to your "real" thread function which then gets called after the wrapper "called" pthread_cleanup_push() . 作为pthread_create()的参数,您传递一个指向“真实”线程函数的指针,然后在包装器“称为” pthread_cleanup_push()之后调用该指针。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM