Today I came across POSIX thread attributes, they are a little weird work with, when you are using them for the first time. I am a little confused about pthread_attr_setdetachstate, which states that:
POSIX threads are in Join state (with the thread which created it) by default but in order to join them, we have to explicitly call
pthread_join()for joining the thread.
Do we need to call pthread_detach explicitly even when the thread attribute is set to detach?
No, you even shouldn’t do that:
So really do either one of them but not both. If you know from the start that you wouldn’t joint the thread, use the variant with the attribute. Depending on your system this might save up some time and memory at the startup of your thread.