tanghai 2 лет назад
Родитель
Сommit
d76b92670b

+ 0 - 2
Unity/Assets/Scripts/Core/Fiber/Fiber.cs

@@ -145,8 +145,6 @@ namespace ET
             }
             this.IsDisposed = true;
             
-            FiberManager.Instance.RemoveReal(this.Id);
-            
             this.Root.Dispose();
         }
     }

+ 9 - 10
Unity/Assets/Scripts/Core/World/Module/Fiber/FiberManager.cs

@@ -104,16 +104,15 @@ namespace ET
         public void Remove(int id)
         {
             Fiber fiber = this.Get(id);
-            fiber.ThreadSynchronizationContext.Post(()=>{fiber.Dispose();});
-            // 这里不能dispose,因为有可能fiber还在运行,会出现线程竞争
-            //fiber.Dispose();
-        }
-        
-        internal void RemoveReal(int id)
-        {
-            this.fibers.Remove(id, out _);
-            // 这里不能dispose,因为有可能fiber还在运行,会出现线程竞争
-            //fiber.Dispose();
+            
+            // 要扔到fiber线程执行,否则会出现线程竞争
+            fiber.ThreadSynchronizationContext.Post(() =>
+            {
+                if (this.fibers.Remove(id, out Fiber f))
+                {
+                    f.Dispose();
+                }
+            });
         }
 
         // 不允许外部调用,容易出现多线程问题, 只能通过消息通信,不允许直接获取其它Fiber引用