Reputation: 59
I want to execute 2 different threads consecutively without using pthread_join, is it alright? or do i really have to declare new thread_t kind of like this:
pthread_create(&th,&thread_attr,shtdwn,(void*)&lpBuffer);
pthread_create(&th,&thread_attr,Run,(void*)&args);
And also I do not need to wait either thread to finish. Your help would be greatly appreciated thanks!
Upvotes: 1
Views: 859
Reputation: 14046
Both the pthread_t
and pthread_attr_t
variables can be re-used for each pthread_create
call. In fact, it is common for the pthread_attr_t
to be reused like that. However, re-using a pthread_t
variable is a bit more unusual as that value is usually stored to be used for subsequent pthread
operations on the thread (such as pthread_join
).
Also, the pthread_attr_t
can be NULL in which case the default attributes will be used. However the pthread_t
argument must not be NULL. From the pthread_create manual:
The attr argument points to a pthread_attr_t structure whose contents are used at thread creation time to determine attributes for the new thread; this structure is initialized using pthread_attr_init(3) and related functions. If attr is NULL, then the thread is created with default attributes.
Before returning, a successful call to pthread_create() stores the ID of the new thread in the buffer pointed to by thread;
Upvotes: 3