Skip to content
Advertisement

Why does pthread_exit use 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).

The only advantage I see is that it lets the programmers define the status how they want (e.g. return a pointer to a complex structure), but I doubt it is widely used like this.

It seems that in most cases this choice has more overhead because of necessary casting.

Advertisement

Answer

This isn’t just for status, it’s the return value of the thread. Using a pointer allows the thread to return a pointer to a dynamically-allocated array or structure.

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.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement