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
1
Question by hnsmith · Feb 18, 2013 at 12:33 AM · coroutinewwwthreadimplementation

WWW class implemented with threads?

Firstly, I would like to clarify that I am aware of the distinction between cooperative multitasking (coroutines/fibers) and true OS threads. Also, I would prefer to avoid answers questioning why I want to know, or whether or not one implementation is more performant than the other in which particular situations, etc. Let's assume that I have a valid reason for asking the question and the only thing that interests me is the specific answer.

I was curious whether or not the underlying implementation of the WWW class spawns a new system thread to manage the download, or whether the download is processed in the main thread.

According to this forum thread: ( http://forum.unity3d.com/threads/67879-Is-Unity-multi-threaded ) unity is single threaded by design to support single core devices, but I have not found any official documentation stating such. Can anyone verify this with official documentation? EDIT: Further in the thread it is mentioned that WWW is one of the only classes that make use of threads...


Update: I attempted to test by using Activity Monitor to watch process thread count while triggering multiple web requests. No new threads were spawned. I thought there could be some heuristic to prevent spawning a thread for small files, or that the threads were being created and destroyed so quickly they weren't displaying in Activity Monitor, so I generated a 1mb garbage file and loaded it and it still did not spawn threads. I served the file from a node.js app in case it was prevent thread spawning for local disk access (URIs with file://). No threads spawned. I served it from an ubuntu vm in case it was optimizing loading from localhost. No threads spawned. Not looking good.


Update 2: Using Process.GetCurrentProcess().Threads.Count I attempted to monitor threads internally. No threads are spawned. This only means that Unity is not spawning threads within the managed CLR though, not that the application is not spawning threads at all. I'm not sure the internal implementation here, but this is looking more and more like a dead end. At least on Mac there doesn't seem to be any threads spawning in the .NET runtime, or as far as I can tell based on procmon either.


Update 3: Process.GetCurrentProcess().Threads.Count is unreliable (Am I using it wrong?). I spawned a thread manually and it continued to return 0, even though ActivityMonitor showed a new thread being added to the Unity process. I added frame delays to give the CLR a chance to register the creation of the thread before querying and it still returned 0. Weird. This does mean, at least, that Unity supports spawning threads on OSX through the Mono runtime. More tests to follow...


Update 4: I thought there might be some implementation differences between the generated standalone and the runtime, or Unity was thread pooling and the threads were never being released. This looks likely! I generated an app file, and it looks like right on cue, 10 threads are spawned when I generate 10 www requests, then they go away afterwards. Maybe not definitive, but good enough for me I guess, unless a developer wants to clue me in on the actual answer.

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
0
Best Answer

Answer by hnsmith · Feb 18, 2013 at 12:44 AM

For those who are curious, I don't have the definitive answer from a developer, but the TL;DR version of my tests are that the WWW class, at least on Mac OSX, is spawning threads in order to process WWW class requests. That's good.

Comment
Add comment · 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

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

9 People are following this question.

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

Related Questions

WWW, RESTful Service, and Threading 1 Answer

i think www blocks display thread 1 Answer

Coroutine needed here? 1 Answer

Yielding with WWW in Editor 9 Answers

suspend a function time to recover a data C# 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