Home > Back-end >  About the join in the thread blocking problem
About the join in the thread blocking problem

Time:12-04

The join of blocking exactly what that means?
Why are the following two pieces of code in vs performed on the effect is not the same?
 
Thread the t1 (func);
Thread t2 (func);
The thread t3 (func);
Thread t4 (func);
Thread t5 (func);
T1. The join ();
T2. The join ();
T3. The join ();
T4. The join ();
T5. The join ();

 
Thread the t1 (func);
T1. The join ();
Thread t2 (func);
T2. The join ();
The thread t3 (func);
T3. The join ();
Thread t4 (func);
T4. The join ();
Thread t5 (func);
T5. The join ();

CodePudding user response:

Each thread is independent, is not the same as normal, isn't it? So the access of data needs to be locked in a thread, synchronization signal

CodePudding user response:

reference 1/f, the truth is right or wrong response:
individual threads are independent, is not the same as normal, isn't it? So the access of data needs to be locked in a thread, synchronous signal

Can you tell me the great god, and to determine whether a thread has begun to perform?

CodePudding user response:

reference FGDDSTFF reply: 3/f
Quote: reference 1/f, the truth is more important than right or wrong response:
individual threads are independent, is not the same as normal, isn't it? So the access of data needs to be locked in a thread, synchronous signal

Can you tell me the great god, and to determine whether a thread has begun to perform?


Add print give it a try? Debugging once know

CodePudding user response:

All threads above is performed first, then all threads waiting completes,
Here is to perform a, wait for its completion, reciprocating the next,
How can the same?

CodePudding user response:

T.j oin () refers to the current code of thread wait () wait for t thread end to continue operation, each thread stack are independent of CPU and code, data sharing, only give it a try

CodePudding user response:

The above is a multi-threaded, the alienation into a single thread,

CodePudding user response:

The first piece of code, 1, began to 2, n, waiting for the end of 1 (may, 2 and 4, n) has ended,
The next piece of code, begin 1, waiting for the end of 1, 2, waiting for the end of the 2, n, waiting for the end of n,

CodePudding user response:

Thread the t1 (func);//have been launched

T1. The join ();
//wait until t1 has been completed
  • Related