[Mono-list] yield

Raja R Harinath rharinath at novell.com
Fri Sep 23 04:54:56 EDT 2005


Hi,

Raja R Harinath <rharinath at novell.com> writes:

I'm continuing since Bernard asked ;-)

[snip]
> To elaborate further on this point, and beat a dead horse:
>
>   * 'yield' allows an arbitrary amount of code to execute.
>
>     - It's like a 'call' in that it breaks the control flow, jumps
>       elsewhere, and comes back when it's done.  
>
>     - It's a co-call, however: unlike a normal function call, you don't
>       know who's at the other end of the yield.

Also,

      - Unlike a function call, it's not exceptional behaviour if
        control doesn't return to the yield.

      - The 'finally' block is executed only if control eventually comes
        back to the 'yield'.  (To make things slightly better, the
        'finally' block is also executed during Dispose.)

      - If anyone uses an iterator which holds the lock, doesn't use
        foreach, doesn't wait for the last iteration, and doesn't call
        Dispose: then you have leaked a lock, and can't get back
        control.  (To make things slightly better, these locks are
        recursive, i.e., they won't deadlock the same thread if it tries
        to re-acquire the lock.)

>   * It's bad to let things you don't control to run inside your lock.

    * It's bad if you can't even predict that your lock will be unlocked
      during the normal course of events

>   => 'yield' and 'lock' don't mix

- Hari


More information about the Mono-list mailing list