Zack
Zack

Reputation: 1235

pthread_self used without pthread_create

I am looking at this example code in http://man7.org/linux/man-pages/man3/pthread_setaffinity_np.3.html

In this example, why pthread_self could be used without pthread_create? I thought a program needs to call pthread_create to create a pthread then calls pthread_self to return the pthread id.

Upvotes: 0

Views: 199

Answers (1)

Alex Lop.
Alex Lop.

Reputation: 6875

pthread_create is used to create a new (usually worker) thread. pthread_self is used to return thread identifier of the thread which calls it. It can also be the main thread.

Upvotes: 2

Related Questions