[swift-users] Recommendation for thread-safe dictionary

Jens Alfke jens at mooseyard.com
Thu Dec 10 13:20:52 CST 2015


> On Dec 10, 2015, at 10:06 AM, Pelaia II, Tom via swift-users <swift-users at swift.org> wrote:
> 
> But isn’t that really a problem with that use case rather than the concurrent dictionary itself?

It’s a problem with _most_ use cases of a concurrent dictionary, unfortunately. The values in such a dictionary can be read and written atomically, but that’s not sufficient for anything that wants to use multiple values in a coordinated way, or update a value, etc. etc.

> It’s not even relevant in my code. I am just using this concurrent dictionary to keep track of concurrent events being completed and posted from different threads. When the event completes it gets put into the dictionary with the value being the immutable result.

That sounds like a case where a simple concurrent dictionary would be an appropriate data structure. So go ahead and write one for your own needs. All we’re saying is that a class like this isn’t commonly useful enough to go into a library.

—Jens


More information about the swift-users mailing list