Threads automatically utilizing multiple CPU cores?

前端 未结 1 2013
执念已碎
执念已碎 2021-01-24 05:57

Assume my application runs 2 threads (e.g. a render thread and a game update thread). If it is running on a mobile device with multi-core CPU (typical nowadays), can I expect th

相关标签:
1条回答
  • 2021-01-24 06:38

    What you need to do is to allow the two threads to run independently as possible. If you have two threads which are always waiting for each other, they might run on the same core to save power. (Because it might appear there is nothing to be gained by having to cores being used)

    the case is the following: first thread decodes a bitmap, while renderer uploads the texture of the previous bitmap to GPU. The first thread goes to sleep if nothing to do; then wakes up if a bitmap needs to be decoded again.

    I suspect this is a good example where two threads won't help because decoding the bitmap should be faster than "uploading" This means you have two situations

    T1: decoding bit map, 
    T2: waiting for a bit map.
    

    or

    T1: sleeping
    T2: uploading a bit map.
    

    or

    T1: sleeping
    T2: waiting for a bitmap.
    

    Can you see how there is no situation where both threads are needing to run (or perhaps rarely) This may be no faster, or even slower than just doing this

    T1: decodes bitmap.
        uploads bitmap.
        waiting for a bitmap.
    
    0 讨论(0)
提交回复
热议问题