The first two articles describe the basics of multithreaded programming in a Linux environment, as well as a typical example. This article mainly compares the Linux environment and the Windows environment of multi-threaded programming differences.
Look at the technical problem to aim at its essence, whether it is WIN32, Linux or VxWorks, its related to the multi-threaded parts are those content, is nothing more than thread control and thread communication, many of their functions are only different names, the essence of the meaning is equivalent, Let's make a list of the three major operating systems in common. Detail form:
| Matters |
WIN32 |
Linux |
VxWorks |
| Thread creation |
CreateThread |
Pthread_create |
Taskspawn |
| Thread termination |
Exit upon completion of execution; The thread itself calls the ExitThread function to terminate itself; Call function TerminateThread function by other thread |
Exit upon completion of execution; Called by the thread itself pthread_exit exits; Call function Pthread_cance terminated by another thread |
Exit upon completion of execution; Exit by calling exit from the thread itself; Call function Taskdelete terminated by another thread |
| Get thread ID |
GetCurrentThreadID |
Pthread_self |
Taskidself |
| Create Mutex |
CreateMutex |
Pthread_mutex_init |
Semmcreate |
| Get Mutex |
WaitForSingleObject, WaitForMultipleObjects |
Pthread_mutex_lock |
Semtake |
| Release Mutex |
ReleaseMutex |
Phtread_mutex_unlock |
Semgive |
| Create semaphore |
CreateSemaphore |
Sem_init |
Sembcreate, Semccreate |
| Wait for the semaphore |
WaitForSingleObject |
Sem_wait |
Semtake |
| Release semaphore |
ReleaseSemaphore |
Sem_post |
Semgive |
Multithreading in Linux environments with multithreaded programming (iii)