AndThis is the SynchronizedValue
is this class (basically a wrapper around a GCD serial queue):
And SynchronizedValue
is this class (basically a wrapper around a GCD serial queue):
This is the SynchronizedValue
class (basically a wrapper around a GCD serial queue):
This is a follow-up to this question.
While discussing some details about the code I posted there, I came upon a problem with thread-safety. After searching and trying different things, I reached a potential solution that I now present here. This worked without any problems during my tests, though since thread-safety is not easy, I'd like to ask: is this implementation genuinely thread-safe?
Here's the code:
- On the computed var
keyValues
, this line.filter { k in k.value != nil }
is needed because a value can become nil while thisdict.get { ... }
block is running, and since the block is still running, the value hasn't been cleaned out yet (the correspondingDeallocWatcher
callback is sitting on the queue waiting for its turn).
Question: I'd like to know if On the computed var keyValues
, this line .filter { k in k.value != nil }
is thread-safeneeded because a value can become nil while this dict.get { ... }
block is running, and since the block is still running, the value hasn't been cleaned out yet (the corresponding DeallocWatcher
callback is sitting on the queue waiting for its turn).
This is a follow-up to this question. While discussing some details about the code I posted there, I came upon a problem with thread-safety. After searching and trying different things, I reached a potential solution that I now present here. This worked without any problems during my tests, though since thread-safety is not easy, I'd like to ask: is this implementation genuinely thread-safe?
Here's the code:
- On the computed var
keyValues
, this line.filter { k in k.value != nil }
is needed because a value can become nil while thisdict.get { ... }
block is running, and since the block is still running, the value hasn't been cleaned out yet (the correspondingDeallocWatcher
callback is sitting on the queue waiting for its turn).
Question: I'd like to know if this is thread-safe.
This is a follow-up to this question.
While discussing some details about the code I posted there, I came upon a problem with thread-safety. After searching and trying different things, I reached a potential solution that I now present here. This worked without any problems during my tests, though since thread-safety is not easy, I'd like to ask: is this implementation genuinely thread-safe?
On the computed var keyValues
, this line .filter { k in k.value != nil }
is needed because a value can become nil while this dict.get { ... }
block is running, and since the block is still running, the value hasn't been cleaned out yet (the corresponding DeallocWatcher
callback is sitting on the queue waiting for its turn).