从线程外部检索pthread_create的arg? [英] Retrieve pthread_create's arg from outside the thread?

查看:109
本文介绍了从线程外部检索pthread_create的arg?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这与如何在pthread包装器中为线程分配唯一ID?当我们需要区分 unique 线程时,我们不能使用类似

When we need to differentiate among unique threads, we cannot use functions like pthread_self because thread ids are reused. In those problems, it was suggested to use a monotonically increasing counter to provide a unique id due to counter potential thread id reuse. The counter is then passed to the thread by way of arg in pthread_create.

由于重用问题,我认为我们无法维护外部线程ID到唯一ID的映射.相同的线程ID可以具有多个唯一ID.

I don't think we can maintain a map of external thread ids to unique ids because of the reuse problem. The same thread id could have multiple unique ids.

我们如何从 线程中检索传递给pthread_createarg?它甚至可以检索吗?

How do we retrieve the arg passed to pthread_create from outside the thread? Is it even retrievable?

推荐答案

我认为我们无法维护外部线程ID到唯一的映射 ids,因为有重用问题.相同的线程ID可能有 多个唯一ID.

I don't think we can maintain a map of external thread ids to unique ids because of the reuse problem. The same thread id could have multiple unique ids.

您可以,只要在此映射中仅保留与当前正在运行的线程相对应的外部线程ID.当线程退出时,您可以将其从地图中删除.

You can, as long as in this map you only keep the external thread IDs corresponding to currently running threads. When a thread exits, you remove it from the map.

地图的用户显然只关心当前正在运行的线程,因为显然,它唯一需要标识的线程就是外部线程ID.

The user of the map obviously only cares about currently running threads, since apparently the only way it has to identify the thread it wants is the external thread ID.

这篇关于从线程外部检索pthread_create的arg?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆