[Mono-list] yield

Bernhard Herzog schwimmlehrer at gmail.com
Wed Sep 14 07:08:25 EDT 2005


> It's a bug in gmcs.
>
> However, using 'lock' and 'yield' together doesn't sound like a good
> idea to me.  The standard doesn't specify anything about releasing and
> re-acquiring the lock around a yield[1]: so, the lock is very
> long-lived.


I have filed a bug report.

>From the Microsoft C# Programmers Reference:
Unsafe blocks are not allowed

My naive unterstanding of how yield works was that code until the loop is 
executed (i.e. the lock is aquired), then the code inside the foreach (the 
one that called the function containing yield) is called and finally the 
code after my loop is called (i.e. the lock is released). In my real life 
example I am iterating through nested Hashtables/Lists and call that from an 
aspx page to generate HTML output. I thought I need to lock the object so 
that the collections are not modified while I am iterating.

I wanted to avoid copying all the data, but maybe there is something that is 
better suited for tasks like that.

Does that make any sense?

Thank you
Bernhard 



More information about the Mono-list mailing list