Reputation: 41
Is Thread.join() a full synchronization with flushing of caches etc. when performed of the thread beeing joined?
Upvotes: 1
Views: 712
Reputation: 1500495
I think you're asking whether from thread T1 that calls join on T2, code in T1 reading data after the join()
will definitely see changes written by T2. If that's the case, then the answer is yes, due to JLS 17.4.4:
The final action in a thread T1 synchronizes-with any action in another thread T2 that detects that T1 has terminated.
T2 may accomplish this by calling T1.isAlive() or T1.join().
and JLS 17.4.5:
All actions in a thread happen-before any other thread successfully returns from a
join()
on that thread.
Upvotes: 5
Reputation: 26926
The method thread.join allows:
one thread to wait for the completion of another. If t is a Thread object whose thread is currently executing,
t.join();
causes the current thread to pause execution until t's thread terminates.
This is not related to synchronization, but only to sequence of steps.
If you have only two threads and you wait the reader thread waits the end of writer thread with method join, this can be used as a mechanism of synchronization, but it is not.
Upvotes: 0