Presentations

14 Monitors

Description
monitrsdf
Categories
Published
of 3
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Related Documents
Share
Transcript
  Operating Systems Lecture Notes Lecture 14 Monitors Martin C. Rinard ã Monitors: A high-level data abstraction tool that automatically generates atomic operations on a given data structure. A monitor has: o Shared data. o A set of atomic operations on that data. o A set of condition variables. ã Monitors can be imbedded in a programming language: Mesa/Cedar from Xerox A!C. ã ypical implementation: each monitor has one loc#. Ac$uire loc# %hen begin a monitor operation& and !elease loc# %hen operation finishes. 'ptimi(ation: reader/%riter loc#s. Statically identify operations that only read data& then allo% these read-only operations to go concurrently. )riters get mutual exclusion %ith respect to other %riters and to readers.Standard synchroni(ation mechanism for accessing shared data. ã Advantages: reduces probability of error *never forget to Ac$uire or !elease the loc#+&  biases programmer to thin# about the system in a certain %ay *is not ideologically neutral+. rend is a%ay from encapsulated high-level operations such as monitors to%ard more general purpose but lo%er level synchroni(ation operations. ã ,ounded buffer using monitors and signals o Shared State   data[10]  - a buffer holding produced data. num  - tells ho% many  produced data items there are in the buffer. o Atomic Operations   Produce(v)  called %hen producer produces data item v . Consume(v)  called %hen consumer is ready to consume a data item. Consumed item put into v . o Condition Variables   bufferAvail  - signalled %hen a buffer becomes available. dataAvail  - signalled %hen data becomes available. ã monitor { ã  Condition *bufferAvail, *dataAvail; ã  int num = 0; ã  int data[10]; ãã  Produce(v) { ã  !ile (num == 10) { * #esa semantics *   ã  bufferAvail$%&ait(); ã  ' ã  ut v into data arra ã  num; ã  dataAvail$%+inal(); * must alas do t!is- * ã   * can relace it! broadcast- * ã  ' ã  Consume(v) { ã  !ile (num == 0) { * #esa +emantics * ã  dataAvail$%&ait(); ã  ' ã  ut ne.t data arra value into v ã  num$$; ã  bufferAvail$%+inal(); * must alas do t!is- * ã   * can relace it! broadcast- * ã  ' ã ' ã he best %ay to understand monitors is that there is a syntactic transformation that insertsthe loc# operations. ã  Condition *bufferAvail, *dataAvail; ã  int num = 0; ã  int data[10]; ã  /oc *monitor/oc; ãã  Produce(v) { ã  monitor/oc$%Acuire(); * Acuire monitor loc $ maes oeration atomic * ã  !ile (num == 10) { * #esa semantics * ã  bufferAvail$%&ait(monitor/oc); ã  ' ã  ut v into data arra ã  num; ã  dataAvail$%+inal(monitor/oc); * must alas do t!is- * ã   * can relace it! broadcast- * ã  monitor/oc$%2elease(); * 2elease monitor loc after erform oeration * ã  ' ã  Consume(v) { ã  monitor/oc$%Acuire(); * Acuire monitor loc $ maes oeration atomic * ã  !ile (num == 0) { * #esa +emantics * ã  dataAvail$%&ait(monitor/oc); ã  ' ã  ut ne.t data arra value into v ã  num$$; ã  bufferAvail$%+inal(monitor/oc); * must alas do t!is- * ã   * can relace it! broadcast- * ã  monitor/oc$%2elease(); * 2elease monitor loc after erform oeration *   ã  ' ã '

ms31

Jul 23, 2017
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks