Are there any monitors in C?

I read the synchronization section in the operating system and read the topic "Monitors". I understand that monitors are high-level language constructs. This makes me wonder if C provides something like a monitor? Perhaps the library containing the implementation of posix streams should also provide monitor design. Also, threads in C are not part of stl, right?

if so, which header file / library contains it, the most basic test program for using monitors and how the library implements monitors.

The book says that the monitor type is ADT - abstract data types. I wonder if structure C creates the syntax of a monitor data type?

Thanks,

+6
source share
4 answers
  • C has no notion of flow and does not provide monitors as a syntax structure.

  • the POSIX thread library is just a library. And C objects of abstraction are not powerful enough to provide the ability to display monitors as a library element. POSIX provides the primitive needed to build monitors.

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

  • to implement a monitor in C, you need a structure whose contents you keep confidential and has at least a mutex, as well as a set of functions that work on the structure, which begin with the adoption of the mutex.

+10
source

C doesn't even support threads, which is implementation specific. You will need to use the library for your monitor.

+2
source

You are correct that threads are not part of the C standard library.

Monitors are not provided in POSIX streams, but everything you can do with a monitor you can do with a mutex plus a condition variable. Or, perhaps, two variable conditions, depending on which monitor you are interested in: http://en.wikipedia.org/wiki/Monitor_%28synchronization%29

+1
source

Streams are for the next version of the C standard only, not the current one. This proposal is very similar to the functionality of POSIX threads and has, for example, mutexes and conditional variables as control structures. AFAIR monitors are not among them.

0
source

Source: https://habr.com/ru/post/889759/


All Articles