- Home /
Is System.Collections.Concurrent or equivalent supported?
I need to use a Concurrent Dictionary or at least some kind of non blocking concurrent collection, is this supported? I get a "namespace name Concurrent' does not exist in the namespace
System.Collections'" error on Unity.
If not, is there an alternative library?
Answer by Bunny83 · Apr 20, 2011 at 01:56 AM
Just take a look at the Mono compatibility page. It's not in the list. Why do you need thread safe collections? You can of course start threads but in Unity it's not that common because the whole API is not thread safe.
Oh, I was looking to the mono compatibility page on mono's site, not unity's, my bad. I am just experimenting with the very basis of a "socket server", but after asking, I realized I don't need Unity at all to make the "server" part so it doesn't matter now :P
The Concurrent Dictionary may be necessary if you want to Serialize Dictionary. And since Unity separate the display thread and modify thread, you might get Race Condition.
For example, you display serialize dictionary on inspector and with an "Add Element" button. You may get IndexOutOfRangeException if you add new dictionary element by press that button.
Answer by snacktime · Aug 19, 2013 at 05:21 AM
What do you mean why do you need thread safe collections? The unity api not being thread safe is no reason to not use threads in unity, it just means don't use their api outside of the main thread. Using thread safe collections or queues to pass information between the main thread and your own threads is perfectly acceptable, given you know what you are doing.
I have a feeling they left it out to discourage people who don't know what they are doing from using threads. But that just forces us to use primitive synchronization which sucks.
Couldn't agree more. I specifically want thread safe collections to pass callbacks to the main thread to invoke. Some bits of Unity are truly excellent (eg shaders), but others (like this) feel half baked.
Your answer
Follow this Question
Related Questions
BurgZurgArcade Tutorial 3 Answers
Best way to store large amounts of data for random generation 1 Answer
How does one get support? 2 Answers
Dual graphics cars support? 2 Answers
Real-Time Ambient Occlusion 0 Answers