diff Implab/AbstractEvent.cs @ 160:5802131432e4 v2

fixed regression: race condition in Promise DFA refactoring
author cin
date Thu, 18 Feb 2016 19:38:54 +0300
parents 97fbbf816844
children 822aab37b107
line wrap: on
line diff
--- a/Implab/AbstractEvent.cs	Thu Feb 18 16:06:14 2016 +0300
+++ b/Implab/AbstractEvent.cs	Thu Feb 18 19:38:54 2016 +0300
@@ -160,8 +160,12 @@
 
                 if (slot < RESERVED_HANDLERS_COUNT) {
 
-                    if (slot == 0)
-                        Interlocked.CompareExchange(ref m_handlers, new THandler[RESERVED_HANDLERS_COUNT], null);
+                    if (slot == 0) {
+                        m_handlers = new THandler[RESERVED_HANDLERS_COUNT];
+                    } else {
+                        while (m_handlers == null)
+                            Thread.MemoryBarrier();
+                    }
 
                     m_handlers[slot] = handler;