Linux_c Development (6-1) multithreaded Programming _ Threading Basics

Source: Internet
Author: User

Multithreadingthreads (thread) technology was introduced in the 60 's, but the real use of multithreading to the operating system, the 80 's mid-term, Solaris is the leader in this area. Traditional UNIX also supports threading concepts, but only one thread is allowed in a process, so multi-threading means multiple processes. Multithreaded technology is now supported by many operating systems, including Windows/nt, Linux. Advantages:compared to the process, it is a very "frugal" multi-tasking mode of operation. Under the Linux system, starting a new process must be assigned to his own space address, creating numerous data tables to maintain his code snippets, stack segments, and data segments, an expensive multi-tasking approach.
multiple threads running in the same process, they use the same address space, and the time it takes to switch between threads is much less than the time it takes to switch between processes. It is estimated that the overhead of a process is about 30 times times the cost of a thread.
The second reason for using multithreading is;a convenient communication mechanism between threads. For different processes , they have a separate data space, which is not only time-consuming but also inconvenient to carry out data transfer only through interprocess communication . Threads otherwise, because data space is shared between threads in the same process , the data of one thread can be used directly by other threads, which is not only fast, but also convenient.
In addition to the advantages described above, multi-threaded process as a multi-tasking, concurrent working mode, has the following advantages:1, the use of CPU system more effective,. The operating system guarantees that when the number of threads is not greater than the number of CPUs, different threads run on different CPUs. 2, improve the program structure. A long and complex process can be considered to be divided into multiple threads, divided into separate or semi-independent parts of the run, which facilitates understanding and modification.
multithreading under a Linux system follows the POSIX threading interface, called Pthread. To write a multithreaded program under Linux, you need to use the header file Pthread.h, you need to use the library when connecting Libpthread.a

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Linux_c Development (6-1) multithreaded Programming _ Threading Basics

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.