首页 >> 编程知识

进程与线程简介、道行越深 编程越凸现算法重要性

进程与线程简介



进程与线程简介

Programs consist of a number of processes, each of which contains one or more conceptually concurrent threads of execution.
程序包含了若干进程,每一个进程包含了一个或多个概念上知执行的线程。

A thread is the unit of execution within a process. Every time a process is initialised, a primary thread is created. For many applications the primary thread is the only one that the application requires; however, processes can create additional threads.
线程是进程的执行单元。当进程被初始化后,主线程就被创建了。对于绝大多数的应用程序来说,通常仅要求有一个主线程。尽管如此进程也可以创建额外的线程。

Each user process has its own private address space, i.e. a collection of memory regions which that process can access. A user process cannot directly address memory areas in the address space of another process. There is also a special process, the Kernel process, whose threads run at supervisor privilege level. This process normally contains two threads:
每一个用户进程拥有自己私有的地址空间,也就是说,进程拥有一定的可被其访问的内存区域。一个用户进程不可以直接访问其他进程的地址空间。另外还有一个特殊的进程,内核进程,它运行在超级用户权限模式。这个进程通常包括两个线程:

the Kernel server thread, which is the initial thread whose execution begins at the reset vector, and which is used to implement all Kernel functions requiring allocation or deallocation on the Kernel heap. This is the highest priority thread in the system.
Kernel server (内核服务器)线程:是一个初始的进程,在系统启动时就已经存在。它可以在heap执行由核心函数请求的内存分配或内存的重分配。这是系统中具有最高权限的线程。

the null thread, which runs only when no other threads are ready to run. The null thread places the processor into idle mode to save power.
null (空)线程:当系统中没有其他可运行的线程时这个线程就开始运行,null 线程使处理器处于空闲状态,减少耗电。

Threads execute individually and are unaware of other threads in a process. The scheduling of threads is pre-emptive, i.e. a currently executing thread may be suspended at any time to allow another thread to run. 

线程是独立运行的,它且并不知道进程中还有其他线程存在。线程的执行是抢占式的,也就是说,当前运行的线程在任何时候都可能被挂起,以便另外一个线程可以运行。

Each thread is assigned a priority; at any time, the thread running is the highest priority thread which is ready to run. Threads with equal priority are time-sliced on a round-robin basis. Context switching between threads involves saving and restoring the state of threads. This state includes not only the processor registers (the thread context) but also the address space accessible to the thread (the process context). The process context only needs switching if a reschedule is between threads in different processes.
每一个线程都设置了优先限权;在任何时候,只要线程已经准备就绪,具有高优先权的线程总是首先运行。如果线程具有相同的悠闲权,则根据时间片进行轮转调度。上下文的切换包括了保存和恢复线程状态。这个状态不仅仅包含了处理器寄存器(进程上下文)而且还包含了线程可访问的地址空间(进程上下文)。只有在重新调度是在两个进程间进行的时候,进程上下文才被切换。

Compare this with active objects which allow non pre-emptive multi-tasking within a single thread.
把这个与活动对象比较,活动对象允许在一个线程中实现非强占式的多任务调度。
A thread can suspend, resume, panic and kill another thread.
一个线程可以被挂起,唤醒、异常抛出和结束其他线程。

When a thread is created it is put into a suspended state, it does not begin to run until that thread’s Resume() member function is called.
线程被创建以后,它处于挂起状态。它没有马上进入运行状态,直到它的Resume()成员函数被调用。

When a thread is created, it is given the priority EPriorityNormal by default. The fact that a thread is initially put into a suspended state means that the thread priority can be changed (RThread::SetPriority()) before the thread is started (RThread::Resume()).
线程创建以后,它具有EPriorityNormal的默认优选级。线程被初始化并处于挂起状态,这意味着在线程开始运行前,线程的运行优先级可以被改变(通过调用RThread::SetPriority()) 。




道行越深 编程越凸现算法重要性



       【CSDN 12月25日】IT是个肥沃而勃勃生机的生态圈,不断孕育着一代又一代的新技术、新概念,而那些站在科技浪尖的自然成为开发者的宠儿。无论IT的浪潮多么朝夕莫测、滚滚而来,计算机和软件发展背后的根基却岿然屹立、经年不变,算法便是基础之一。

       我国著名的计算机教育专家、信息学奥林匹克竞赛国家队总教练和领队吴文虎可谓桃李满天下,带过的学生包括张朝阳等,而在IT开发领域的学生更是不在少数。据他称,他的许多在软件领域的学生表示,在工作初期多会追随新潮和时髦的技术,但随着工作年龄的增加和编程技术的深入,却发现不是具体的技术而是算法这些基本的东西成为了技术深入的软肋,而且这跟软肋很疼。记者从几位在软件界工作了十数年的技术人员中了解到,往往技术了解得越多、做得东西越深,这样的体会越明显。



       吴文虎表示,造成这种情况,我国的计算机教育方式也难逃其咎。传统的“程序设计基础”等课程过于强调语句、函数、技术名词、书本例子等细节,而应强调程序设计的实践性,在课程内容上则应当重点放在思路、算法、编程构思和程序实现上。

       “算法”也不仅仅是数学概念里的狭隘算法,这里指是指计算机领域的对问题的思考方式以及解决步骤,是一种思路和逻辑性的体现。所以吴文虎建议开发者不要太计较算法领域里的专业术语,也不要被一些论文和书本里的称谓给吓倒,重要的是解决问题的思路和扎实的作风。

       很多算法已经被包装到了语言和工具中,这也成为不少开发者逃避学习算法的借口。吴文虎认为这其中的算法往往只适用于本语言或工具而且只能解决某些问题,移植到别的情况下则无法使用。况且这种算法已经因为语言或者工具而界定了思路,开发者很难有自己的思维方式,难以用于其他方面和实际中。

       不仅如此,如果没有自己的思维方式和编程逻辑,很容易对某种具体的技术或者工具产生依赖性,而这些工具和技术多是国外开发的。如果在需要的地方而又没有现成的怎么办?“只要有了计算机算法的思维方法,什么都不怕。”吴文虎说。

       Ruby之父松本行弘就曾表示,注重的是算法而不是工具,实际表达的是与吴文虎一样的意思。所以,吴文虎建议开发者尤其是编程初学者和入门者,趁年轻脚踏实地,打下坚实的基础。

进程与线程简介、道行越深 编程越凸现算法重要性(本文完毕)
下一篇:Asp.net网站性能优化总结[C#为例]
上一篇:简单是一种美:提高项目成功率的一些方法