I’m doing some threading of a socket server and I want to use a concurrent object to manage storage and access of data across threads. I am trying to use ConcurrentDictionary from the System.Collections.Concurrent namespace, but Unity keeps telling me the namespace doesn’t exist.
Apparently this namespace and it’s classes were added with .NET 4.0. Is Unity utilizing an older version? Is there a way I can add this namespace to the build path?
Unity isn’t using the current release of Mono, I think.
I don’t know exactly what the current versions are, that information should really be easier to find. It should be listed on the 2.6 Scripting page, then again on the 3.0 page.
Well this isn’t very good… so now I need a solution for either creating a ConcurrentDictionary class or some other way to allow for safe multi-thread access to data without locking…
generally all datastructures from System.Collections are thread safe.
Generally because in mono 1.2.5 as it is used in unity at the time, the implementation of threads is flacky and I would consider to still lock them for altering operations.
Question is what you need them for.
Assuming you didn’t know about the .NET fact you are currently not using threads anyway (coroutines run in the main thread).
I am running a continuous while loop in a threaded function which is constantly checking a socket for any incoming UDP data. It’s important that this is threaded as we expect fluctuating amounts of data that need to be parsed at the same time that graphics are continually rendered. I just need to be sure that I can create a dictionary of objects that will constantly be updated by the threaded function as well as constantly accessed and read by scripts throughout the scene.