isn't a Gem
尝试一发Node.js

monitors

violet posted @ Apr 03, 2014 04:13:32 PM in 胡扯 , 14715 阅读

这又是啥!!! 今天看面试题的时候看到 monitors VS semaphore, 简直就是这是啥! monitors是啥! 啥啥啥...
让你不好好看书!搜索了一发于是来写总结...

monitors是比较high-level的控制多线程的结构, 素这样的

Typical implementation: each monitor has one lock. Acquire lockwhen begin a monitor operation, and Release lock when operationfinishes. Optimization: reader/writer locks. Statically identifyoperations that only read data, then allow these read-only operationsto go concurrently. Writers get mutual exclusion with respect to otherwriters and to readers. Standard synchronization mechanism for accessing shared data.

结构素这样的

monitor { 
  Condition *bufferAvail, *dataAvail;
  int num = 0;
  int data[10];

  Produce(v) { 
    while (num == 10) { /* Mesa semantics */
      bufferAvail->Wait();  
    }
    put v into data array
    num++;
    dataAvail->Signal(); 
 }
  Consume(v) { 
    while (num == 0) { /* Mesa Semantics */
      dataAvail->Wait();
    } 
    put next data array value into v
    num--; 
    bufferAvail->Signal(); 
  }
}

这不就是mutex么, 互斥锁啊...论两家都有一只狗, 只有一个花园, 狗见狗, 狗咬狗, 放个mutex万事大吉...

等等, 那还用个java啊! mutex还不够么

不够啊, mutex是对一个进程一个进程进行处理, 如果想批量操作, 请用monitors...论一边是基佬们, 一边是百合们, 只有一个花园, 我们要烧死异性恋, 嗯, 用monitors!

那...那monitors和semaphore啥区别, monitors是共享可见的啊少女! 然后看到了这个解释

A monitor is like a public toilet. Only one person can enter at a time. They lock the door to prevent anyone else coming in, do their stuff, and then unlock it when they leave.

A semaphore is like a bike hire place. They have a certain number of bikes. If you try and hire a bike and they have one free then you can take it, otherwise you must wait. When someone returns their bike then someone else can take it. If you have a bike then you can give it to someone else to return --- the bike hire place doesn't care who returns it, as long as they get their bike back.

monitors是全局共享可见, 比较high-level, semaphore由自己定义, 有自己的作用域, 可以用semaphore实现monitors

噢...

还是不会用, 还要研究研究怎么用.

引用:

http://people.csail.mit.edu/rinard/osnotes/h14.html

  • 无匹配
  • 无匹配
NCERT Hindi Question 说:
Sep 30, 2022 05:16:51 PM

Hindi is the mother language in various North states of the country and it is First Language for all Hindi Medium Students, various students of other mediums like English & Urdu are chosen Hindi as a Second or Third Language subject from the optional languages. NCERT has introduced Hindi Language Sample Paper suggestions for all medium students who have chosen Hindi as their 1st Language, NCERT Hindi Question Paper Class 9 2nd Language or 3rd Language subject.Hindi is the mother language in various North states of the country and it is First Language for all Hindi Medium Students.

navodayaresults.in 说:
Apr 29, 2023 05:59:36 PM

The students who have appeared or participated in JNVST 5th to 6th Class Admission Selection Tests and IXth Class Vacant Seat Lateral Entry tests they can check their result from the listed nearest educational offices in your circle and navodayaresults.in district wise and zone wise selected candidate list with merit or toppers lists will be published at the Navodaya Vidhyalaya official website as per schedule.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter