I need to have a multithreaded (or thread safe) data structure management lib.
Write (exclusive) locking may occur on a part of the structure when modifications are needed. Due to a wide range of subroutines called within exclusive lock operations being recursive, possibly comming round the same parts of the structure, I want to know if calling lock() on the same thing, in one thread, will block or not, or at least if there's some defined behaviour. Neither perlfunc lock or perlthrtut had any information on this.
I suppose the most logical work around will be to maintain a nonshared hash of locked parts.
The scheme is a reference to a semaphore, within the lockable part. Shared locks are granted by locking to the reference, and upping the semaphore by one. The lock is then released, and upon cease of shared use, the semaphore is downed witout locking.
Exclusive locks are granted by locking on the reference, and waiting for the semaphore to hit zero. when the lock on the reference goes out of scope, the exclusive lock is tossed.
-nuffin
zz zZ Z Z #!perl
Edit by tye to fix typo noted in reply
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.