New course! Every coder should learn Generative AI!
Try a free lesson0
As for standard libraries, Semaphore provides all this functionality and much more. If you only want one thread in the critical section at a time check out synchronized methods orlocks. Look at the javadoc forjava.util.concurrent.locks.AbstractQueuedSynchronizer. It has an example of how to write a Mutex class