Open nepolak opened 1 week ago
I understand that using a lock is the most reliable approach. However, for ReactiveProperty (and Subject), I want to avoid using locks. I'd like to know the conditions under which race conditions occur, and based on that, choose a better solution.
I understand that using a lock is the most reliable approach. However, for ReactiveProperty (and Subject), I want to avoid using locks. I'd like to know the conditions under which race conditions occur, and based on that, choose a better solution.
That's understandable.
It may occur like this:
Subscribe
on a ReactiveProperty
, receives current value, but is not subscribed yet. It stays here: https://github.com/Cysharp/R3/blob/4fc537d03444c102f323abd2242852be59f1c7b6/src/R3/ReactiveProperty.cs#L213OnNext
is being called and a new value is written and pushed without synchronization: https://github.com/Cysharp/R3/blob/4fc537d03444c102f323abd2242852be59f1c7b6/src/R3/ReactiveProperty.cs#L116And so, although the items were pushed like this:
What the observer sees is:
The 'Second' is left missing, and so observer thinks the current value is First. This is depicted in the log in this comment (third run): https://github.com/Cysharp/R3/issues/229#issue-2372532001
Fixed some tests, results of which were dependent on the platform used.
Fixed ReactiveProperty race condition
Also (seems to be) mentioned in https://github.com/Cysharp/R3/issues/229