Bug 12536 - Not all delegates are called if combined in an unusual order
Summary: Not all delegates are called if combined in an unusual order
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: JIT ()
Version: unspecified
Hardware: PC Linux
: Normal normal
Target Milestone: ---
Assignee: Rodrigo Kumpera
URL:
Depends on:
Blocks:
 
Reported: 2013-06-04 10:20 UTC by Alexander Gavrilov
Modified: 2013-06-11 15:09 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Minimal demonstration. (654 bytes, text/x-csharp)
2013-06-04 10:20 UTC, Alexander Gavrilov
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Alexander Gavrilov 2013-06-04 10:20:51 UTC
Created attachment 4062 [details]
Minimal demonstration.

The usual way for adding individual delegates to a list is via +=, which adds a single callback to the end of the list.

If instead you try adding it to the beginning via "callbacks = NewCB + callbacks", the callback list already contains multiple entries, and has already been called at least once, the new callback will be added without error, but won't be called.

I think the reason for this may be that this call to SetMulticastInvoke should actually be moved between the two loops, and use the value of clone at that point, so as to affect the actual point where the two lists are joined:
 
https://github.com/mono/mono/blob/master/mcs/class/corlib/System/MulticastDelegate.cs#L157

In the usual one-item case the first loop doesn't do anything, so there is no difference and the code works.
Comment 1 Rodrigo Kumpera 2013-06-11 15:09:26 UTC
Fixed on master. Thanks for the test case.