简体   繁体   中英

Threads automatically utilizing multiple CPU cores?

Assume my application runs 2 threads (eg 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 that threads are assigned to different cores automatically when possible?

I know the underlying OS kernel (Android linux kernel) decides scheduling. My question is whether I need to do anything additional to enable multi-core usage, or is it automatic and transparent?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM