When is it safe to call pthread_attr_destroy?
Asked Answered
B

1

13

I am using pthreads on Linux. From the documentation, it is not clear to me when it is safe to call pthread_attr_destroy on the attributes I use to create a new thread? Can I do it immediately after pthread_create returns or do I have to wait until the thread is joined or detached?

Thanks in advance, Christoph

Buckle answered 5/2, 2013 at 14:47 Comment(0)
B
19

The thread attribute is copied in pthread_create, so it should be destroyed after pthread_create call.

Requires reading between lines here http://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_create.html:

If the attributes specified by attr are modified later, the thread's attributes shall not be affected.

Boom answered 5/2, 2013 at 14:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.