Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Signal thread-safe #191

Closed
ulex opened this issue Dec 24, 2020 · 0 comments
Closed

Make Signal thread-safe #191

ulex opened this issue Dec 24, 2020 · 0 comments

Comments

@ulex
Copy link
Collaborator

ulex commented Dec 24, 2020

Current Signal implementation use a thread-unsafe LifetimedList as a backend. There are some exception-protecting mechanisms in LifetimedLists, which significantly reduce the probability of exception during Advise/Fire, but they can't protect in all cases. Since it is allowed to use arbitrary schedulers for RdSignal, reliable thread-safe solution is required here.

Sample test to violate existing implementation:

[Test]
public async Task TestSignalStress()
{
  var sig = new Signal<bool>();
  using (var run = new LifetimeDefinition())
  {
    var lt = run.Lifetime;
    var sw = Stopwatch.StartNew();
    var fireTask = Task.Run(() =>
    {
      while (sw.ElapsedMilliseconds < 500 && lt.IsAlive) 
        sig.Fire(true);
    }, lt);

    Parallel.For(0, 100000, i =>
    {
      using (var ld = new LifetimeDefinition())
        sig.Advise(ld.Lifetime, x => { });
    });

    await fireTask;
  }
}
Iliya-usov added a commit that referenced this issue Dec 30, 2020
Fix incorrect AddPriorityItem
+ tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant