Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by sirrandalot · Aug 07, 2017 at 10:30 PM · freezeprocedural generationproblem during runtimethreadsthreading

Best Practice for Multithreading Procedural Terrain Generation?

I'm trying to make infinite procedurally generated chunk based terrain. Because the generation of block data and vertex/triangle arrays takes a while I'm trying to put as much as I can on a second thread.

Currently I have a background thread checking which chunks need to be loaded, generating them if they're not already calculated and adding them to a dictionary of chunks to load which my main thread then looks at during the regular update cycle and uses to instantiate the generated chunks. This approach seems to be working in theory, the logic is sound at least and the chunks generate and are instantiated as they should be but the background thread just stops working after a little while. It seems to stop arbitrarily (sometimes 2 seconds, sometimes 20 seconds) although notably I can get it to stop by causing a spike in the rendering requirements (suddenly looking at an area of the world which has a lot stuff to render).

Checking the thread state reveals that it is alive but not running. It's not being blocked by the main thread because if I comment out all the critical sections from the main thread, the background thread still freezes after a few seconds of running.

I've tried using

     lock(lockObject){}  

as well as

     AutoResetEvent.WaitOne()  

but the problem persists. I'm not sure if the structure I've set up isn't really conducive to decent multithreading or if I'm misusing the thread synchronization methods/keywords.

If it is the way I've structured my program, how would I structure it in such a way that works? And if it isn't that, then what is it about the way I'm using threads that's causing things to go wrong? Thanks!

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 Bunny83 · Aug 07, 2017 at 10:58 PM

Well, it highly depends on your actual implementation and what kind of interactions happen between your threads. Keep in mind when a exception is thrown inside your thread, the thread will get terminated silently. However IsAlive will not be false in this case because it returns:

true if this thread has been started and has not terminated normally or aborted; otherwise, false.

You may want to check the ThreadState instead. However if an exception is thrown it would make more sense to track down the actual problem which is the cause of the exception.

Again you haven't provided any information which could help to track down the issue.

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 sirrandalot · Aug 08, 2017 at 01:16 AM 0
Share

I didn't realise that background threads are ter$$anonymous$$ated silently if they throw an exception, this was indeed the case. After fixing what was causing the exception to be thrown it works fine, thanks!

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

70 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity crashes sporadically when threading 1 Answer

Multithreading freezes editor 1 Answer

What does new Thread do, and how many threads are too many? 1 Answer

Performing "transform.Rotate" in it's own thread 1 Answer

Runtime error printing another thread 2 Answers


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