Grasshopper

algorithmic modeling for Rhino

Hello all,

is <GH_Structure> thread-safe? Has anyone ever tried populating a GH_Structure with data from multiple threads?

I. e. is it similar to Net 4's ConcurrentDictionary? Or will it fail when multiple threads try to store data at the same time?

Not a big issue, I can bypass it by locking it upon access or by using a ConcurrentDictionary and turning it into a GH_Structure only upon passing data back to GH, but I though I'd ask out of curiousity...

Cheers,

Dan

P.S.: A very quick test returned some KeyNotFound Exceptions

Views: 389

Replies to This Discussion

No. Practically nothing is thread-safe in GH1.

And there are no plans to make the GH_Structure<T> equivalent in GH2 threadsafe either. The problem is that the items within branches are ordered, and if you are writing items to branches from multiple threads then the ordering is basically up for grabs.

It would be possible to make several tree methods threadsafe, but of course that comes at a performance cost. I think it'll be more likely that I'll provide a thread-safe tree factory class that can be used in those rare cases where it's needed.

ok cool. As I mentioned I can work around the issue without problem by having a little class to convert ConcurrentDictionaries into GH_Structure before passing data back to GH. 

Thanks!

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service