TDPL, shared data, and Phobos
"Jérôme M. Berger"
jeberger at free.fr
Fri Jul 23 11:57:19 PDT 2010
Graham St Jack wrote:
> Priority inheritance chaining goes like this:
>
> Thread low locks mutex A, then mutex B
>
> Thread high tries to lock mutex B, elevating low's priority to high's so
> that high can get the mutex quickly.
>
> When thread low releases mutex B (letting high get it), the OS has
> trouble figuring out what low's priority should now be, and leaves it
> elevated until it releases all mutexes it still has (mutex A in this case).
>
> Low is now running at a high priority, preventing thread medium from
> getting any CPU.
>
>
> This scenario happened for me with vxWorks some time back, and is the
> reason I no longer do much work at all while I have a mutex locked. I am
> confident that it is a real problem to this day.
>
This is only a problem on real-time OSes where high priority
threads prevent low priority ones from running at all. On non
real-time OSes like Windows, Linux, *BSD and MacOS, low priority
threads will always get some CPU cycles too, and AFAIK thread
priorities are never elevated in the way you describe.
That being said, it is always a good practice to spend as little
time as possible holding a lock (whether a mutex or a file lock or
whatever).
Jerome
--
mailto:jeberger at free.fr
http://jeberger.free.fr
Jabber: jeberger at jabber.fr
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20100723/c9da0048/attachment.pgp>
More information about the Digitalmars-d
mailing list