Nepedia
Back to Discover
Fluent Reader
💻

Monitor (synchronization)

technology Maturity 11-13 war conflict Next article →

This article covers sensitive topics: war_conflict. Parents can manage visibility in Parental Controls.

Computers often run many tasks at once. These tasks are called threads. Sometimes, many threads need to use the same piece of information. If they all try to change it at the exact same time, they can cause big mistakes. These mistakes are called data races or logical errors. A monitor is a special tool that keeps this sharing safe. It acts like a manager for a shared object.

Monitor (synchronization)-SU
Monitor (synchronization)-SU

A monitor works using two main parts. The first part is called a mutex, which is a type of lock. When a thread wants to use the object, it must first lock the mutex. This creates something called mutual exclusion. This rule means only one thread can use the object at any single moment. While one thread is working, all other threads must wait their turn. Once the thread finishes, it unlocks the mutex so others can enter.

Monitor (synchronization)-Mesa
Monitor (synchronization)-Mesa

Sometimes, a thread cannot finish its job right away. It might need to wait for something specific to happen first. For example, a thread might need to wait until a list is not empty. Instead of checking the list constantly, which wastes computer power, the thread can sleep. This is where condition variables come in. A condition variable is a way for a thread to wait for a change in state.

Monitor (synchronization)-Java
Monitor (synchronization)-Java

When a thread waits on a condition variable, it does something very clever. It temporarily gives up its lock so other threads can enter the monitor. This allows other threads to change the object and make the condition true. Once the change happens, a thread sends a signal. This signal wakes up the sleeping thread. The sleeping thread then tries to grab the lock again to finish its task.

Scientists Per Brinch Hansen and C. A. R. Hoare invented monitors. Brinch Hansen first used them in a language called Concurrent Pascal. Monitors help solve classic problems like the producer-consumer problem. In that problem, one thread makes tasks and another thread uses them. The monitor ensures the maker does not add to a full list. It also ensures the user does not try to take from an empty list. This keeps the whole system running smoothly without errors.

366 words

Where will your curiosity go next?

Keep exploring at your chosen reading level.

🖼️ Images & Media (3)
File:Monitor (synchronization)-SU.png
Monitor (synchronization)-SU.png
File:Monitor (synchronization)-Mesa.png
Monitor (synchronization)-Mesa.png
File:Monitor (synchronization)-Java.png
Monitor (synchronization)-Java.png
More to explore

What is Nepedia?

A free, ad-free encyclopedia for children. Every article is written at five reading levels, so the same page works for a five-year-old and a fifteen-year-old — use the level switcher above to see this one change. No account needed to read.