I'm getting confused on the idea of "pthread" and "thread". I know pthread is short form for POSIX thread, which is a type of standardized thread used in UNIX. But people often use "thread" to refer a thread. Are pthread and thread equivalent? Or pthread is only the name for threads used in UNIX? Thanks in advance.
PThreads is a highly concrete multithreading system that is the UNIX system's default standard. PThreads is an abbreviation for POSIX threads, and POSIX is an abbreviation for Portable Operating System Interface, which is a type of interface that the operating system must implement.
Pthread uses sys_clone() to create new threads, which the kernel sees as a new task that happens to share many data structures with other threads. To do synchronization, pthread relies heavily on futexes in the kernel.
Yes, the pthreads library is still used for threading.
In a Unix/Linux operating system, the C/C++ languages provide the POSIX thread(pthread) standard API(Application program Interface) for all thread related functions. It allows us to create multiple threads for concurrent process flow.
Threads are a generic concept. Wikipedia defines it as:
In computer science, a thread of execution is the smallest sequence of programmed instructions that can be managed independently by an operating system scheduler. A thread is a light-weight process.
Pthreads or POSIX threads are one implementation of that concept used with C program on Unix. Most modern languages have their own implementation of threads. From that web page:
Pthreads are defined as a set of C language programming types and procedure calls, implemented with a pthread.h header/include file and a thread library - though this library may be part of another library, such as libc, in some implementations.
To add to Gray,
Pthread is POSIX complaint which means you can use it across most of the UNIX operating systems.
No need to rewrite them for each of Unix (Linxux,FreeBSD, etc) and the behavior would be same across all of them .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With