Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by MasterLG · Jul 11, 2013 at 08:41 AM · multithreading

Thread synchronization and .NET version issues

I'm just doing some tests to see if multithreading can improve the performance of my physics engine add-on.

The code's core concept does work. However, I've been using "poor man's barriers" so far by creating/joining threads as necessary. I'm amazed that got any performance gains at all, but it did. However, I think I could get even more if I created the threads once and then use a Barrier to synchronize them.

The problem I run into is that, from what I gather, Unity uses version 2.0 of the .NET framework, whereas version 4.0 is where the Barrier first appeared for .NET.

I've tried recreating my own version of a barrier. Although functional, it's horribly inefficient.

So, would there be any way to...

  • have Unity use .NET 4.0 or newer version of .NET

  • use Barriers with .NET 2.0 (or whatever Unity uses)

  • use something like a barrier with .NET 2.0 (or whatever Unity uses) that isn't just thread creation/joining every cycle

If yes to any of those, how?

Alternatively, if Unity is MEANT to use .NET 4.0 or newer, how can I solve the problem of it not being able to 'see' the Barrier class when I include System.Threading?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by CHPedersen · Jul 11, 2013 at 09:19 AM

Bulleted answers your questions:

  • There is no user-accessible way to have Unity use .Net 4.0. We're stuck on horrible Mono 2.6 until UT decides to spend some resources building an up-to-date version of Mono into their engine. Last time I heard they said they'd try to make it in the 4.0 release cycle, but in truth, there is no set-in-stone promise about when it will happen.

  • There is no way to use Barriers with .Net 2.0 that I know of.

  • Thread synchronization in Unity is accomplished in the "old-fashioned way" with locking mechanisms and blocking. Use the lock keyword to protect shared variables. Use the AutoResetEvent class or the Semaphore class to cause threads to block until signaled to continue. Use the Monitor class to restrict access to objects.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MasterLG · Jul 11, 2013 at 10:45 PM 0
Share

Well, that sucks. However, I did find a workaround that works a lot like Barriers based on the information you provided.

$$anonymous$$anualResetEvents can be made to work like Barriers if you build around them a little.

EDIT: Corrected a typo

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Using BackgroundWorker Class let Unity crash. 2 Answers

CompareBaseObjectsInternal can only be called from the main thread. 1 Answer

Multithreaded Input Detection 2 Answers

Unity Multithreading only works partial 0 Answers

Getting texture size off main thread 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges