TAILIEUCHUNG - Advanced Linux Programming: 4-Threads
Tham khảo tài liệu 'advanced linux programming: 4-threads', công nghệ thông tin, hệ điều hành phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Threads Threads like processes are a mechanism to allow a program to do more than one thing at a time. As with processes threads appear to run concurrently the Linux kernel schedules them asynchronously interrupting each thread from time to time to give others a chance to execute. conceptually a thread exists within a process. Threads are a finer-grained unit of execution than processes. When you invoke a program Linux creates a new process and in that process creates a single thread which runs the program sequentially. That thread can create additional threads all these threads run the same program in the same process but each thread may be executing a different part of the program at any given time. We ve seen how a program can fork a child child process is initially running its parent s program with its parent s virtual memory file descriptors and so on copied. The child process can modify its memory close file descriptors and the like without affecting its parent and vice a program creates another thread though nothing is copied. The creating and the created thread share the same memory space file descriptors and other system resources as the original. If one thread changes the value of a variable for instance the other thread subsequently will see the modified value. Similarly if one thread closes a file descriptor other threads may not read 62 Chapter 4 Threads from or write to that file descriptor. Because a process and all its threads can be executing only one program at a time if any thread inside a process calls one of the exec functions all the other threads are ended the new program may of course create new threads . GNU Linux implements the POSIX standard thread API known as pthreads . All thread functions and data types are declared in the header file .The pthread functions are not included in the standard C library. Instead they are in libpthread so you should add -Ipthread to the command line when you link your .
đang nạp các trang xem trước