vlingo-net / xoom-net-actors

Type safe Actor Model toolkit for reactive concurrency and resiliency using C# and other .NET languages.
Mozilla Public License 2.0
39 stars 18 forks source link

Replace Thread.Sleep() calls with safer/better alternatives #26

Closed tjaskula closed 5 years ago

tjaskula commented 5 years ago

There are many calls to Thread.Sleep which is not the best alternative in concurrent code.

VaughnVernon commented 5 years ago

@tjaskula Can you indicate where the Thread.Sleep() uses are? There may be a few in tests, which is not the greatest choice, and will inevitably fail. However, there should pretty much never be Thread.Sleep() in the library code. I think there may be one possible use of Thread.Sleep() when the World is terminating. I don't remember. In such case it could still be replaced with a better construct as you suggest.

tjaskula commented 5 years ago

Except tests there are actualy two places in:

VaughnVernon commented 5 years ago

@tjaskula Yes, thanks for the reminder. I would be perfectly happy if both of these Sleep() uses went away. Eventually Stop() will be async in that the Sweep() will be actor-based and return immediately. At that point we will need an atomic indicator that Sweep() and Stop() have fully completed, and we will need to aggregate that indicator into a single one when stopping multiple Stage containers. (The default container is always created, but the application/service can start any number of others.)

tjaskula commented 5 years ago

I’ll take care of that

tjaskula commented 5 years ago

Backoff is addressed in #29

tjaskula commented 5 years ago

@zpbappi @VaughnVernon Why we need that when stopping a stage in Stage.Stop():

while (Count > 1 && ++retries < 10)
            {
                try { Thread.Sleep(10); } catch (Exception) { }
            }
tjaskula commented 5 years ago

This is not more relevant