Complete event firing twice
Status: Beta
Brought to you by:
nythrix
When adding an event handler to an Complete event already completed the event handler is fired twice in some cases. First it is called in
"public event ComputeCommandStatusChanged Completed"
then it is called again in
"protected virtual void OnCompleted(object sender, ComputeCommandStatusArgs evArgs)".
I think this is a problem arrising from multi-threading and I am not sure if Cloo is intended to be used in a multi-threading environment. Nevertheless, for me it can be fixed by not adding the event handler to "completed" in "public event ComputeCommandStatusChanged Completed" if
"status.Status == ComputeCommandExecutionStatus.Complete".
The problem really seems to be about thread-safety. It appears if one thread adds an event handler to Completed while the StatusNotify callback is executed.
Adding a lock to Completed+= as well as StatusNotify resolves the problem in my tests. Attached you find a patch with my changes.
Last edit: Alex 2013-01-18