Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there monitors in C?

I am reading synchronization chapter in Operating system and am reading the topic "Monitors". I understand that monitors are high level language constructs. This makes me wonder if C provides something like monitor? Perhaps the library containing posix threads implementation should provide the monitor construct as well. Also, threads in C are not part of stl, right?

if yes, which header file/library contains it, a most elementary test program to use monitors and how the library implements monitors.

The book says a monitor type is an ADT - abstract data types. I wonder, does a C structure simulate a monitor data type?

Thanks,

like image 585
xyz Avatar asked Jun 04 '11 07:06

xyz


People also ask

What is a monitor in C?

In concurrent programming, a monitor is a synchronization construct that allows threads to have both mutual exclusion and the ability to wait (block) for a certain condition to become false. Monitors also have a mechanism for signaling other threads that their condition has been met.

What are monitors in operating system?

What is a monitor in OS? Monitors are a programming language component that aids in the regulation of shared data access. The Monitor is a package that contains shared data structures, operations, and synchronization between concurrent procedure calls. Therefore, a monitor is also known as a synchronization tool.

Which of the following language supports monitor?

Some languages that do support monitors are Java,C#,Visual Basic,Ada and concurrent Euclid.

What is a monitor in Java thread?

Monitor in Java Concurrency is a synchronization mechanism that provides the fundamental requirements of multithreading namely mutual exclusion between various threads and cooperation among threads working at common tasks. Monitors basically 'monitor' the access control of shared resources and objects among threads.


2 Answers

  • C has no notion of thread and doesn't provide monitors as syntactic structure.

  • the POSIX thread library is just a library. And C abstraction facilities are not powerful enough to allow monitors to be provided as library element. POSIX gives the primitive needed to build monitors.

  • STL is a C++ term (and not even a good one as it means different things for different people).

  • to implement a monitor in C, you'd need a structure whose content you keep private and has at least a mutex, and a set of functions operating on the struct which start by taking the mutex.

like image 195
AProgrammer Avatar answered Sep 19 '22 00:09

AProgrammer


C doesn't even have support for threads, that's implementation specific. You'll need to use a library for your monitor.

like image 27
David Heffernan Avatar answered Sep 19 '22 00:09

David Heffernan