为什么pthread_exit使用void *?

I recently started using posix threads and the choice of argument types in the standard made me curious. I haven't been able to asnwer the question of why does pthread_exit use void* instead of int for the returning status of the thread? (the same as exit does).

我看到的唯一好处是,它可以让程序员按自己的意愿定义状态(例如,返回指向复杂结构的指针),但是我怀疑它是否像这样被广泛使用。

似乎在大多数情况下,由于必须进行转换,因此此选择会产生更多开销。

评论
  • zearum
    zearum 回复

    这不仅仅是状态,它是线程的返回值。使用指针允许线程将指针返回到动态分配的数组或结构。

    You can't really compare it with the exit() parameter, because that's for sending status to the operating system. This is intentionally very simple to allow portability with many OSes.