<"Clive Dixon" <clived at digita dot com>wrote:
>
Thanks for the article, and keep up the good work.
Do you think it would be explicitly worth mentioning locks in the
article? I talk about using statements, but not locks...
It might be worth mentioning Jon, it's a potential pitfall for the unwary.
Righto. I've added this paragraph:
<article>
It's worth remembering that most finally blocks in code aren't written
explicitly in C# - they're generated by the compiler as part of lock
and using statements. lock is particularly dangerous in iterator blocks
- any time you've got a yield return statement inside a lock block,
you've got a threading issue waiting to happen. Your code will keep
hold of the lock even when it has yielded the next value - and who
knows how long it will be before the client calls MoveNext() or
Dispose()? Likewise any try/finally blocks which are used for critical
matters such as security shouldn't appear in iterator blocks: the
client can deliberately prevent the finally block from executing if
they don't need any more values.
</article>
Do you think that covers it?
--
Jon Skeet - <sk***@pobox.com>
Web site:
http://www.pobox.com/~skeet
Blog:
http://www.msmvps.com/jon.skeet
C# in Depth:
http://csharpindepth.com