Android单核线程

发布于 2024-12-07 14:24:07 字数 219 浏览 0 评论 0原文

只是想知道使用一个处理器进行线程是否可以改善我的情况。 我正在构建一个应用程序,该应用程序在 UI 运行且需要平稳运行时执行数据密集型计算(对 pcm 数据进行 fft)。

我一直在研究 AsyncTask,但在想:

如果我的 Optimus One 上运行的是单核处理器(600 MHz ARM 11 处理器),线程会有所不同吗?我认为要使线程独立运行,您需要多个处理器?还是我哪里出错了?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小矜持 2024-12-14 14:24:07

为了保证响应能力,必须让主线程或 UI 线程去做 UI 事情。这不包括游戏中的密集绘图或 3D 渲染。当您开始在主线程中执行计算密集型操作时,用户会看到延迟。一个经典的例子:

单击按钮时,睡眠(1000)。将此与单击按钮时启动一个处于休眠状态的 AsyncTask (1000) 进行比较。

异步任务(和其他线程)允许应用程序“同时”处理计算和 UI 交互。

就并发如何工作而言,上下文切换是游戏的名称(如 Dan 所言)。

单核CPU上的多线程不会提高你的性能。事实上,与上下文切换相关的开销实际上会降低您的性能。然而,当用户对 UI 感到沮丧并直接关闭应用程序时,谁会关心应用程序的运行速度?

当然,Asynctask 是可行的方法。

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.

可是我不能没有你 2024-12-14 14:24:07

请参阅开发指南文章响应式设计

Android 使用 Linux 内核和其他专用软件来创建 Android 操作系统。它使用多个进程,每个进程至少有一个线程。单个(和多个)处理器硬件平台上的多线程是通过上下文切换来完成的。这给人一种每个处理器同时运行多个线程的错觉。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文