Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a class monitor in D?

D2.0 classes have a __monitor class property that "gives access to the class object's monitor" (documentation). I searched around a bit and did not find any information except for this bit of detail. So: what is a monitor? Why is one monitor used for all synchronized member functions? Is it a synchronization primitive used for synchronizing member functions similar to Java? And why is the __monitor property in the language def if you are not supposed to use it / what are the use-cases?

like image 633
stephan Avatar asked Mar 08 '10 06:03

stephan


People also ask

What is a class monitor?

(especially formerly) a student appointed to assist in the conduct of a class or school, as to help take attendance or keep order. a person appointed to supervise students, applicants, etc., taking an examination, chiefly to prevent cheating; proctor.

What can I expect from a class monitor?

A class monitor is responsible for passing out papers in their classroom, take attendance, and clean up after classes have ended. They are also expected to provide feedback on how things could be improved at school assemblies or other school events that they attend with their teachers.

What is the role of monitor in school?

The incumbent in this class is responsible for the supervision of students and student activities and for maintaining order in school buildings, school district public libraries, on school grounds and playgrounds, and at street crossings.

What will you do if you become a monitor?

A class monitor is a student who assists the teacher in routine duties. They maintain class discipline in the teacher's absence and lead the class through various activities. They should act as a role model for the rest of the students.


1 Answers

The monitor is a lazily initialized object that all synchronized methods synchronize on, just like in Java. Unlike Java, D is a systems programming language and exposes lower level details of how things work just in case you need to hack them, even if doing so is usually a bad idea. This allows you to customize behavior. For example, it is possible to customize the monitor object of a class, or to use a core.sync.mutex that shares a monitor with the class that owns it.

like image 177
dsimcha Avatar answered Nov 05 '22 12:11

dsimcha