Fiber don't stop

Options
Eldar9x
edited January 2012 in Photon Server
        static void Main(string[] args)
        {
            IFiber fiber = new PoolFiber();
            fiber.Start();

            fiber.Enqueue(() => Console.WriteLine("Before Dispose"));

            fiber.Dispose(); // stop fiber;

            fiber.Enqueue(() => Console.WriteLine("After Dispose"));

            Console.ReadKey();
        }

But output is:
Before Dispose
After Dispose

Why Dispose() don't stop fiber?

Comments

  • Perhaps, there is a bug in the implementation PoolFiber.
    The Dispose() method change state to ExecutionState.Stopped;
    And in the original Retlang, it checks its:
           public void Enqueue(Action action)
            {
                if (_started == ExecutionState.Stopped)
                {
                    return;
                }
    
                //skipped
            }
    

    But ExitGames.Concurrence.Fibers.PoolFiber don't check its ExecutionState.Stopped state in the Enqueue() method...

    Sorry for my english :)
  • Yury
    Options
    Interesting what version of Retlang using?
  • Tobias
    Options
    As far as I know, we modified the Fiber for our usecase. In some cases, we needed to execute the messages that are still in the fiber, despite closing it for further messages.
    The colleague who knows this part best is on vacation, so Ill point him to this discussion next week.
  • Before I found this error, I used the Fibers from ExitGames.dll. But now I use actual version Retlang from website. It is develop for .NET 4.0, so I change source code and build for .NET 3.5
  • As far as I know, we modified the Fiber for our usecase. In some cases, we needed to execute the messages that are still in the fiber, despite closing it for further messages.
    The colleague who knows this part best is on vacation, so Ill point him to this discussion next week.
    Ok:
    IFiber fiber = new PoolFiber();
    fiber.Start();
    fiber.Enqueue(() =>
        {
            System.Threading.Thread.Sleep(5000); 
            Console.WriteLine("1");
        });
    fiber.Enqueue(() =>  Console.WriteLine("2"));
    fiber.Dispose(); 
    /*
    fiber already have disposed, but we need get 1 and 2 ("we needed to execute the messages that are still in the fiber, despite closing it for further messages.")
    */
    fiber.Enqueue(() =>  Console.WriteLine("3")); // not to be displayed in any case ("despite closing it for further messages.")
    
    Console.ReadKey();
    

    Output is normal in both cases (Retlang and ExitGamesLibs):
    1
    2

    But in ExitGames.Concurrency.Fibers we obtain additional "3"...
  • Thanks for response!