Multi-process is the basic image of the operating system
Is it possible to switch sequences of instructions without moving resources?
Process = resource + instruction execution sequence
- Threads: preserves the benefits of concurrency and avoids the cost of process switching
- The real thing is that the mapping table is constant and the PC pointer changes
are multiple execution sequences + one address space practical?
A Web browser
- A thread is used to receive data from the server
- A thread used to display text
- A thread is used to process pictures (such as decompression)
- A thread used to display pictures
Do these threads share resources?
- The received data is placed at 100 and is read when displayed.
- All the text and pictures are displayed on one screen
Start implementing this browser ...
void Webexplorer ()
{char url[] = "http://cms.hit.edu.cn";
Char buffer[1000];
Pthread_create (..., GetData, URL, buffer);
Pthread_create (..., Show, buffer); }
void GetData (char *url, char *p) {...};
void Show (char *p) {...};
Create? Yield?
The core is yield ...
- Can switch to know what to do when switching ( look to understand, the rest is to write the program to achieve this look ... )
- Create is the way to create the first time you switch.
Take a closer look at yield, that's 100 jump to 300.
Two execution sequences with one stack ...
(3) What happens if we go further down the board?
How to solve the problem?
Why?
From a stack to a stack of two ...
Yield Toggle to switch the stack first, then ...
- (3) What happens if we go further down the board?
- 204 is called Yield () to press the stack ...
void Yield() {
TCB1.ESP=ESP;
ESP=TCB2.ESP;
JMP 204; should be removed
}
Two threads: Two TCB, two stacks, switched PCs in the stack
The core of Threadcreate is to use the program to make these three things .
void Threadcreate (A)
{
TCB *tcb=malloc ();
*stack=malloc ();
*stack = a;//100
Tcb.esp=stack;
}
Combine all things together ....
Gcc-o Explorer get.c yield.c ... or GCC get.c. -lthread
GetData will call yield () when downloading to text ...
Why is it that user-level threading--yield is a user program
If a thread of a process enters the kernel and blocks, then ...
Core-Level threadsWhat is the difference between a core-level thread and a user-level thread?
Threadcreate is a system call that goes into the kernel and the kernel knows the TCB
- Gcc-o Explorer explorer.c yield.c ...
- Kernel-level thread Gcc-o Explorer explorer.c ... ; Threadcreate is a system call; Yield () The user is not visible, the dispatch point is determined by the system
[No000039] Operating system operating systems user-level thread users Threads