Lock
When reading and writing data globally, if atomic operations cannot be guaranteed, it is easy to pollute the data.
Such as:
import threading
import time
from threading import Lock
l = [0]
def func():
num = l[0]
time.sleep(0.001)
l[0] = num + 1
threads = []
if __name__ == '__main__':
for i in range(100):
...
Posted by Wynder on Thu, 19 May 2022 05:28:58 +0300
Design mode - single case mode - eight different implementations [JAVA] and single case problem sorting - necessary for interview - super detailed
Introduction to singleton mode
the singleton pattern is a software design pattern that restricts the instantiation of a class to one "single" instance. It can be simply understood as: a class ca ...
Posted by SalokinX on Mon, 16 May 2022 21:13:29 +0300
Java thread pool must know and know
To know why it is, we should know why it is. In the process of using thread pool, do you understand why we should do this and how to configure thread pool to have better effect?
Why should thread pool be used
Thread pool is actually a way of using multithreading. In terms of design, it is a production c ...
Posted by beanfair on Sun, 15 May 2022 23:50:25 +0300
1, Foreword
This paper will introduce a case that the main thread actively delete s the sub thread object, resulting in the main thread jamming (infinite waiting);
2, Cited examples
1. Case description
1) The implementation includes a main thread and a sub thread;
2) The main thread is responsible for starting the child thread and dest ...
Posted by asy1mpo on Fri, 13 May 2022 15:36:10 +0300
📕 Mutex and deadlock
1, Data sharing issues
First, let's look at the execution order of multithreading:
void TextThread() {
cout << "I am a thread:" << this_thread::get_id() << endl;
//In thread operation code
cout << "thread " << this_thread::get_id() << "End of operation" << endl;
}
int main()
{
...
Posted by rd321 on Thu, 12 May 2022 09:14:46 +0300
How to implement java multithreading? There are two common methods: 1) Integrate the Thread class and override the run() method 2) Implement the Runnable interface and the run() method of the interface
1, Integrate the Thread class and override the run() method
Start a new Thread by calling the start() method of Thread class and execute the ...
Posted by phpDVWeaver on Thu, 12 May 2022 08:56:14 +0300
Causes of occurrence
When multiple statements are operating on the same thread to share data, one thread only executes part of multiple statements, and another thread participates in the execution. The error that caused the shared data.
Examples
class Window implements Runnable{
private int ticket = 10;
@Override
public void run ...
Posted by Nytemare on Thu, 12 May 2022 08:23:32 +0300
Class RandomAccessFile
Instances of this class support reading and writing random access files. Random access to a file behaves like a large number of bytes stored in a file system. There is a cursor, or index to an implicit array, called a file pointer; The input operation reads the bytes starting from the file pointer and causes the file poi ...
Posted by kreoton on Wed, 11 May 2022 11:51:50 +0300
Let's first look at processes and threads Process is the smallest unit of computer scheduling resources Thread is the smallest unit of process scheduling resources. A process has at least one thread
Four ways to create threads in java
1. Inherit the Thread class and override the run() method. The run method is the task to be executed
Ad ...
Posted by RwpTechAdMin on Wed, 11 May 2022 05:17:27 +0300
Several basic knowledge points of thread scheduling
When multi-threaded concurrent execution, many students do not know what problems will be caused by the randomness of scheduling. It is necessary to know that if access to critical resources is not locked, it will lead to some emergencies or even deadlocks.
Regarding thread scheduling, you nee ...
Posted by Adrianphp on Tue, 10 May 2022 04:36:15 +0300