[Haskell-cafe] Re: Optimizing locking with MVars

Bulat Ziganshin bulat.ziganshin at gmail.com
Thu May 4 00:55:29 EDT 2006


Hello John,

Thursday, May 4, 2006, 12:33:54 AM, you wrote:

>> This won't affect Handle I/O unfortunately, because we need block to
>> protect against asynchronous exceptions.  I'm still not certain you 
>> won't need that in the stream library, too: check any stateful code (eg. 
>> buffering) and imagine what happens if an exception is raised at an 
>> arbitrary point.

> Is unlocking the lock really the right thing to do on an asynchronous
> exception? A lock isn't a resource, it is a primitive needed to enforce
> correctness of your program. You use them to protect critical sections
> and chances are aborting a critical section at an arbitrary point would
> leave your program in an incorrect state, just delaying your deadlock or
> hiding the errors silently somewhere where they can bite you later.

after Simon's message i thought about this problem. i found several
situations where "restoring" of locked file will be useful:

- using stdout and other standard handles. we may need to print error
message or just continue work despite the exception abandoned our
previous writing to stdout

- access to database. despite the exception arrived during previous
operation, we need to go further and just hSeek to the position of
next I/O operation



-- 
Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com



More information about the Haskell-Cafe mailing list