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 par开发者_开发技巧t 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,
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.
C doesn't even have support for threads, that's implementation specific. You'll need to use a library for your monitor.
You're right that threads are not part of the standard C library.
POSIX threads don't provide monitors specifically, but everything that you can do with a monitor, you can do with a mutex plus a condition variable. Or possibly two condition variables, depending exactly what kind of monitor you're interested in: http://en.wikipedia.org/wiki/Monitor_%28synchronization%29
Threads are only foreseen for the next version of the C standard, not the current one. The current proposal resembles very much the functionality of POSIX threads, and has e.g mutexes and conditional variables as control structures. AFAIR monitors are not among them.
精彩评论