Why must threads wait and wake up locked?

when any thread X executes the wait () and notify () methods on any thread Y, it needs to acquire the lock first.
it is said that the locking mechanism is to solve the critical resource problem, so does it allow threads to start and pause access to any critical resources? Can
wait and wake up threads in a way similar to interrupts and messages instead of locks?
Please don"t hesitate to give me advice.


wait () and nitify () are used to solve the problem of critical resources. If a critical resource is in a thread and the thread cannot execute for other reasons, we need to wait (), the critical resource so that other threads can call the critical resource.
if, as you say, it is not a critical resource, then you do not need to use the wait method, because it does not affect other threads, and other threads will not block at all


waiting and waking up objects are critical resources, otherwise why should the thread wait, right?

Menu