History of thread development-1

1. History of processes and threads

1. Single-process manual switching
  • tape machine
2. Multi-process batch processing
  • Batch execution of multiple tasks
3. Multi-process parallel processing
  • Write the program in different memory locations and switch back and forth
4. Multithreading
  • Switching back and forth between different tasks within a program (the concept of threads)
  • selector -> epoll (kernel level upgrade, multiplexing)
5. Fiber/coroutine
  • Green threads, user-managed (rather than OS-managed ) threads.

2. The difference between program, process, thread and fiber

1. Procedure
Overview: executable files, such as .exe, etc.;
2. Process
Overview: Resource allocation by the OS operating system ( the basic unit of resources );
process:
1. An app is distributed through the operating system;
2. The IO bus gets the app to build a bridge, and then transfers the app data to the memory through the memory bus;
3. When the memory gets the app, it is stored in the memory as a process, and the main function Main is executed and given to the CPU;
3. Thread
Overview: the basic unit of execution of a process ;
4. Fiber/coroutine
Overview: the basic unit of execution of a thread ;

3. 6 states of threads

1. new (new thread, not started)
2. runnable (runnable state, thread executor can be scheduled)
3. waiting (waiting to be woken up, wait, notify, lock, unlock)
4. timed waiting (timed waiting sleep, wait)
5. blocked (blocked thread is blocked, waiting for a lock, only in synchronized-waiting to enter a synchronous code block)
6. terminated (the thread ends the current thread)
Thread end method:
  1. stop - has been deprecated and is not recommended for use. The operation is rough and prone to data consistency problems. Use: thread.stop();
  2. Method 2 suspend (pause) / resume (resume execution) - has been deprecated, this method has been deprecated because it is inherently prone to deadlock. If a target thread holds a lock on a monitor protecting a critical system resource while suspended, no thread can access that resource until the target thread resumes.
  3. Method 3 uses volatile to define a variable for the number of executions to control the end of the thread and manually set the flag bit. The disadvantage is that it cannot accurately control the timing of closing.
  4. Method 4 Method 4 interrupt (interrupted) / interrupted (whether the current thread is interrupted) (interrupted) Set the mark position similar to volatile, set the thread as an interrupt mark, and then the thread checks whether there is a thread, and if it exists, set it The thread ends.

Guess you like

Origin blog.csdn.net/weixin_43869435/article/details/126577979