Monitors: Mesa & Hoare

Hoare

  • "wait": causes the calling program to be delayed
  • "signal": causes exactly one of the waiting programs to be resumed immediately.
Hoare Mesa Java
Monitor Lock ALL entry Synchronized[1]
Condition Vars Y No/yes (one implicit CV per object)
Wait Yes Y Yes
Signal Yes Y -> nofify & Broadcast Yes notify(), notifyAll()
Granularity/粒度 module Monitor class & Monitor record Monitor/instance, sync. Blocks
Aborts No Unwind handler, reestablish invariant KILL, STOP[3]
Nested calls No Yes4 Yes5
  • [1] Every object is a monitor. More than half of the code implementing Object class is about synchronization.
  • [2] 1. Synchronized block; 2. Class / Instance associated synchronization
  • [3] KILL and STOP have already been deprecated in Java. Instead, a thread t0 set a variable to show the intention to kill another thread t1. t1 then does the clean-up and do the stop.

How are the semantics of wait and notify different

  • Java is similar to Mesa.
  • In Mesa, wake up only when …
  • In Hoare immediately exe ( go back to the ready q) -- guaranteed to get into the monitor.
  • In Mesa, cons: need to check again. Pros: fairness,

Hoare

  • Signal immediately transfer control

Mesa

  • while (not invariant) wait (c)

Questions

Why did Mesa make this change

  • Performance: extra context switches
  • Remove scheduling from inside of monitor

Where do the extra context switches come from?

  • (S -- Signal Process, W -- Wait Process)
  • Hoare: S switch to W, W goes, have to swtich back to S
  • Mesa:

Why Java does not use condition variables

  • simplicity of a single lock per object or class

Why does Mesa have monitor records as well as monitor modules?

  • fine-grained concurrency (并发性)
  • Note that Java chose fine-grained as the default

Mesa Handling aborts

  • Mesa has explicit support for shutting down a process such that it can establish the monitor invariant before dying.

What are the implications for Java where threads can be killed?

  • JVM has to release locks

A network socket is an endpoint of a connection across a computer network. Today, most communication between computers is based on the Internet Protocol; therefore most network sockets are Internet sockets.

Priority

priority inversion is a problematic scenario in scheduling in which a high priority task is indirectlypreempted by a medium priority task effectively "inverting" the relative priorities of the two tasks.

  • 将low priority task临时提高priority,快点运行完(运行完之后,再降回),这样high priority就不用一直等着那个resource了。一直等着就是说每次轮到CPU了,却只能等/被唤出。

results matching ""

    No results matching ""