Re: Multitasking and containers



"Dr. Adrian Wrigley" <amtw@xxxxxxxxxxxxxxxxxxxxxxxxxxx> writes:

Actually, I think Dmitry's view is largely valid in practice, if
somewhat extreme.

But we were talking specifically about using a protected object to implement a
multiple readers schema vs. using a protected object to implement a Hoare-style
monitor. Because reads must by synchronized, the standard container library
requires a monitor-style synchronization scheme.

The OP made the argument that this isn't very efficient, and Dmitry responded
by saying, "well of course systems require custom hand-made solutions." But the
premise is all wrong, so what Dmitry said is irrelevant. The OP (not Dmitry)
seems to be confused (he was asking the question, after all) about the
difference between a mutex and a monitor. He (the OP) probably doesn't
understand that monitor-type synchronization executes on the current thread, so
there's no context switch, and so there's no efficiency loss.

The only time when monitor-style synchronization would be inappropriate is if
the protected operation needed to make a "potentially-blocking call," but
that's not the case here so there's no reason (certainly there's no efficiency
reason) not to use a monitor.
.