Android Threading with single core

爷,独闯天下 提交于 2019-12-11 02:46:23

问题


Just wondering if threading with one processor improves things for me. I am building an application that performs data intensive calculations (fft on pcm data) while a UI is running and needs to run smoothly.

I have been looking at AsyncTask but was thinking:

If I have a single core processor (600 MHz ARM 11 processor) running on my Optimus One, will threading make a difference? I thought for threads to run independantly you would need multiple processors? Or have I gone wrong somewhere?


回答1:


In order to guarantee responsiveness, it is imperative to leave the main or UI thread to do the UI things. This excludes intensive drawing or 3d rendering in games. When you start to do computationally intensive things in your main thread, the user will see lag. A classic example:

on a button click, sleep(1000). Compare this with, on a button click, start an AsyncTask that sleeps(1000).

An asynctask (and other threading) allows the app to process the calculations and UI interactions "simulataneously".

As far as how concurrency works, context switching is the name of the game (as Dan posts).

Multithreading on a single core cpu will not increase your performance. In fact, the overhead associated with the context switching will actually decrease your performance. HOWEVER, who cares how fast your app is working, when the user gets frustrated with the UI and just closes the app?

Asynctask is the way to go, for sure.




回答2:


Take a look at the Dev Guide article Designing for Responsiveness.

Android uses the Linux kernel and other specialized software to create the Android Operating System. It uses several processes and each process has at least one thread. Multi-threading on a single (and mutiple) processor hardware platform is accomplished by context switching. This gives the illusion of running more than one thread per processor at a time.



来源:https://stackoverflow.com/questions/7641164/android-threading-with-single-core

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!