CST 334 - Operating Systems (Week 5)

 This week's material is quite interesting also. Concurrency, an important topic especially for game developers. Because no matter what, I will have to face a bigger and more complex project that requires the use of thread in concurrency, sooner or later. Therefore, I want to share my knowledge about thread related to Unity.


First and foremost, I encountered the yield() in thread of C language. It makes a process gives up CPU control and requeue on scheduling. That is, another process gets its turn. It quickly reminds me of yield in Unity. At the first glance, they both have similar concept: it "pauses" the current process/task and let other runs. However, the Unity's yield does not requeue that task. Instead, it will return after a certain amount of time and keep going until it finishes. You can think of this concept as many people (as many tasks in Unity) are in waiting room. And every minute, one person (the task with yield) will come up and ask for his/her paper.


The yield() in this week's material is concurrency or multi-thread. Meanwhile, the Unity's yield() is known as coroutine, and it is still a single thread. The good thing about this concept is the task that put to yield is kept as minimal, consuming only a little memory, while other tasks are running. Because it is simple and quite convenient, Unity community mostly recommend using coroutine instead of thread. Of course, that does not mean coroutine is perfect and thread is complete bad. There are problems with coroutine that Unity developer has to take care of. And when facing bigger, more complex projects, multi-thread is coming in handy. But that is for later, when I have enough knowledge and confidence to handle it.

Comments

Popular Posts