For many years, maximum computer performance was limited largely by the speed of a single microprocessor at the heart of the computer. As the speed of individual processors started reaching their practical limits, however, chip makers switched to multicore designs, giving the computer the opportunity to perform multiple tasks simultaneously. And although OS X takes advantage of these cores whenever it can to perform system-related tasks, your own applications can also take advantage of them through threads.
多年来,大多数计算机性能极大地受到了单片微处理器的限制(电脑的心脏),随着单处理器达到它们性能的极限,芯片生厂商转向了多核设计,给予计算机同时执行多任务成为可能。OS X利用了多核使得无论什么时候它都可以执行系统相关任务。
你自己的应用程序也可以利用他们通过thread。
线程是什么呢?
Threads are a relatively lightweight way to implement multiple paths of execution inside of an application. At the system level, programs run side by side, with the system doling out execution time to each program based on its needs and the needs of other programs. Inside each program, however, exists one or more threads of execution, which can be used to perform different tasks simultaneously or in a nearly simultaneous manner. The system itself actually manages these threads of execution, scheduling them to run on the available cores and preemptively interrupting them as needed to allow other threads to run.
Threads相对轻量级的方式实现了在程序中执行多任务。在系统层面,程序并发执行,随着系统的需要和其他程序的需要,系统提供给他们相应的时间。然而在每个程序中,存在一个或多个执行的线程。可以同时或者几乎同时的执行多任务。系统本身管理着这些线程的执行,调度它们在可用的内核上运行并且预先中断它们来允许其他的线程运行。
From a technical standpoint, a thread is a combination of the kernel-level and application-level data structures needed to manage the execution of code. The kernel-level structures coordinate the dispatching of events to the thread and the preemptive scheduling of the thread on one of the available cores. The application-level structures include the call stack for storing function calls and the structures the application needs to manage and manipulate the thread’s attributes and state.
从技术角度来看,线程是管理代码执行所需的内核级和应用级数据结构的组合。内核级结构协调事件的调度到线程,并且在一个可用内核上线程的抢占式调度。应用程序级结构包括用于存储函数调用的调用栈和应用程序管理和处理线程的属性和状态所需的结构。
In a non-concurrent application, there is only one thread of execution. That thread starts and ends with your application’s main routine and branches one-by-one to different methods or functions to implement the application’s overall behavior. By contrast, an application that supports concurrency starts with one thread and adds more as needed to create additional execution paths. Each new path has its own custom start routine that runs independently of the code in the application’smainroutine. Having multiple threads in an application provides two very important potential advantages:
Multiple threads can improve an application’s perceived responsiveness.
在一个无并发的程序中,仅仅有一个线程。该线程以程序main函数开始和结束,并逐个分支到不同的方法或函数来实现应用的所有行为。相比之下,支持并发的程序从一个线程开始,并根据需要添加更多的线程创建更多的执行路线。每个path都利用线程有自己的开始路径在程序中同时独立的跑那段代码。多线程提供来了两个非常明显的优势。
1.Multiple threads can improve an application’s perceived responsiveness.
多线程可以改善程序的响应能力。
2.Multiple threads can improve an application’s real-time performance on multicore systems.
多线程可以提高多线程在多核系统上的实时性能
1.线程简单来说就是内核和需要处理任务的结合。
2.内核协调需要处理的事件到线程,并且给优先级较高的线程安排可用内核。