CN1328877C - Sharing route realizing and sheduling method - Google Patents
Sharing route realizing and sheduling method Download PDFInfo
- Publication number
- CN1328877C CN1328877C CNB011390808A CN01139080A CN1328877C CN 1328877 C CN1328877 C CN 1328877C CN B011390808 A CNB011390808 A CN B011390808A CN 01139080 A CN01139080 A CN 01139080A CN 1328877 C CN1328877 C CN 1328877C
- Authority
- CN
- China
- Prior art keywords
- thread
- threads
- state
- event
- running
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Expired - Fee Related
Links
Landscapes
- Debugging And Monitoring (AREA)
Abstract
一种涉及数据处理操作平台中线程的实现和调度方法,涉及一种可避免或减少进行内核线程切换,充分利用处理器效率,并减少系统资源消耗的共享线程实现和调度技术。所述方法采用下列步骤:以完成线程控制块的设置和线程绑定的线程创建、起动运行的线程激活、接受事件触发转入运行状态的线程运行、完成线程状态切换,就绪及运行队列管理等的线程调度和完成线程数据的清除,线程标识释放,调整系统线程数量的线程的退出。本发明的方法,充分减少了线程的切换时间;并在不增加系统资源消耗的前提下,充分利用系统资源,提供数量巨大的线程机制,以保证多线程编程在线程上的消耗。
The invention relates to a thread realization and scheduling method in a data processing operation platform, and relates to a shared thread realization and scheduling technology which can avoid or reduce kernel thread switching, make full use of processor efficiency, and reduce system resource consumption. The method adopts the following steps: to complete the setting of the thread control block and the thread binding thread creation, start the thread activation of operation, accept the thread operation triggered by the event and transfer to the running state, complete the thread state switching, ready and run queue management, etc. Thread scheduling and clearing of thread data, release of thread ID, and exit of threads that adjust the number of system threads. The method of the invention fully reduces the switching time of threads; and without increasing the consumption of system resources, fully utilizes system resources and provides a huge number of thread mechanisms to ensure the consumption of threads in multi-thread programming.
Description
技术领域technical field
本发明涉及一种数据处理操作平台中共享线程的实现和调度方法。具体的说,涉及一种可避免或减少进行内核的线程切换,充分利用处理器效率,并减少系统资源消耗的共享线程实现和调度方法。The invention relates to a method for realizing and scheduling a shared thread in a data processing operation platform. Specifically, it relates to a shared thread implementation and scheduling method that can avoid or reduce kernel thread switching, fully utilize processor efficiency, and reduce system resource consumption.
背景技术Background technique
在典型的多任务操作系统中,系统的内存空间由硬件强制分成用户空间和内核空间,用户程序仅能运行在用户空间,当需要使用内核时,需要执行特殊的陷阱指令。传统的进程多任务系统就是基于这样的结构,进程控制结构的全部信息都处于内核空间,每次进程的切换都会涉及到对内核空间的访问。In a typical multitasking operating system, the memory space of the system is divided into user space and kernel space by hardware. User programs can only run in the user space. When the kernel needs to be used, special trap instructions need to be executed. The traditional process multitasking system is based on such a structure. All the information of the process control structure is in the kernel space, and each process switching will involve access to the kernel space.
多线程技术允许一个程序同时执行多个任务,并共享进程空间中的资源。与传统以进程为单位的多任务操作系统不同,线程是轻量级实体,线程结构中相当一部分在用户空间,允许快速的访问。正是由于线程的这种特征,多线程技术得到了广泛的应用,编制多线程程序可以得到如下的好处:充分利用多处理器的并发能力而得到优秀的性能;提高程序的吞吐量和反应能力;减少进程间通讯开销,有效的利用系统资源;无需修改程序,即可以在单处理器或多处理器上使用。Multithreading technology allows a program to execute multiple tasks simultaneously and share resources in the process space. Unlike traditional multitasking operating systems that use processes as units, threads are lightweight entities, and a considerable part of the thread structure is in user space, allowing fast access. It is precisely because of this characteristic of threads that multithreading technology has been widely used. Compiling multithreaded programs can obtain the following benefits: make full use of the concurrent capabilities of multiprocessors to obtain excellent performance; improve the throughput and responsiveness of programs ; Reduce inter-process communication overhead and effectively use system resources; without modifying the program, it can be used on a single processor or multiple processors.
线程是通过编写线程库实现的,目前有两种线程库实现方法。第一种方法是编写用户级库,依赖与已有的内核功能,最主要的库调用在用户空间执行;第二种方法是编写内核级库,大部分库调用运行于内核空间,需要系统调用支持。POSIX标准的某些实现属于第一种方法,而OS/2和Win32线程属于第二种方法。由于操作系统内核只了解进程结构(后期存在轻量级进程LWP),线程库的主要任务之一就是将线程通过某种方法绑定到内核识别的进程或是LWP上,从而由内核实现线程的并发。随着线程数量的增加,系统将会面临两个问题。一是,线程数量的增加将会消耗内核绑定进程(LWP)的数量,而这一内核资源是有限的;二是,线程数量的增加将导致线程切换次数的增加,每次线程的切换将可能导致内核的访问开销,切换花费的时间完全是额外的。鉴于上述的问题,在多线程的实际应用上存在着一定的限制,首先线程数量不能太大,其次,线程数量到达一定数量时,系统整体性能不能提高,甚至出现下降。同时,每一个线程都是一个独立的运行实体,但是在线程的整个生命周期中,线程并不是时时刻刻都在工作,大量的时间花费在等待可用资源上,这无疑是一种浪费。Threads are implemented by writing a thread library. Currently, there are two thread library implementation methods. The first method is to write a user-level library, which depends on existing kernel functions. The most important library calls are executed in user space; the second method is to write a kernel-level library. Most library calls run in kernel space and require system calls. support. Certain implementations of the POSIX standard fall into the first approach, while OS/2 and Win32 threads fall into the second. Since the operating system kernel only understands the process structure (there is a lightweight process LWP in the later stage), one of the main tasks of the thread library is to bind the thread to the process or LWP recognized by the kernel in a certain way, so that the kernel realizes the thread. concurrent. As the number of threads increases, the system will face two problems. One is that the increase in the number of threads will consume the number of kernel-bound processes (LWP), and this kernel resource is limited; May cause access overhead to the kernel, the time spent switching is completely extra. In view of the above problems, there are certain limitations in the practical application of multithreading. First, the number of threads should not be too large. Second, when the number of threads reaches a certain number, the overall performance of the system cannot be improved, or even decline. At the same time, each thread is an independent running entity, but in the entire life cycle of the thread, the thread does not work all the time, and a lot of time is spent waiting for available resources, which is undoubtedly a waste.
发明内容Contents of the invention
本发明的目的在于提出一种共享线程实现和调度方法,充分减少线程的切换时间;并在不增加系统资源消耗的前提下,充分利用系统资源,提供数量巨大的线程机制,以减少多线程编程在线程上的消耗。The purpose of the present invention is to propose a shared thread implementation and scheduling method, fully reduce the thread switching time; and under the premise of not increasing the consumption of system resources, make full use of system resources, provide a huge number of thread mechanisms, to reduce multi-thread programming Consumption on threads.
本方法所涉及的线程分为两种,用户线程和系统线程,其中用户线程是本方法实现的线程,系统线程是由其他线程库提供的线程机制,用户线程构筑在系统线程之上。下文提及的线程均指用户线程。The threads involved in this method are divided into two types, user threads and system threads, wherein user threads are threads implemented by this method, system threads are thread mechanisms provided by other thread libraries, and user threads are built on system threads. The threads mentioned below refer to user threads.
线程的构成包括线程标识,线程入口和事件接收区几个主要部分,这几个部分由线程控制块管理,线程控制块处于用户空间。整个线程的实现和调度方法如下:The composition of thread includes several main parts of thread identification, thread entry and event receiving area, these parts are managed by thread control block, and thread control block is in user space. The implementation and scheduling method of the entire thread is as follows:
一种共享线程实现和调度方法,采用下列步骤:A method for implementing and scheduling a shared thread, using the following steps:
1、线程创建,以完成线程控制块的设置和线程绑定,线程控制块的设置包括1. Thread creation to complete the setting and thread binding of the thread control block. The setting of the thread control block includes
线程入口设置、事件接收区地址申请及线程状态初始化;Thread entry setting, event receiving area address application and thread state initialization;
2、线程激活;2. Thread activation;
3、线程运行;以接受事件触发转入运行状态,并与系统线程绑定,对当前的事件处理结束后,重新转入空闲状态,并与系统线程分离。3. The thread is running; it enters the running state triggered by the acceptance event, and binds to the system thread. After the current event processing is completed, it returns to the idle state and separates from the system thread.
4、线程调度,线程调度包括下列步骤:4. Thread scheduling, thread scheduling includes the following steps:
a、线程系统维护就绪线程队列和运行线程队列;a. The thread system maintains the ready thread queue and the running thread queue;
b、由主线程和其他线程创建每一个线程;b. Each thread is created by the main thread and other threads;
c、当空闲线程有事件触发时,事件的发出方在发送事件的同时将接收线程从空闲状态转入就绪状态,并将该线程放入就绪线程队列;c. When the idle thread is triggered by an event, the sender of the event will transfer the receiving thread from the idle state to the ready state while sending the event, and put the thread into the ready thread queue;
d、系统线程阻塞等待在就绪线程队列上,一但有线程进入就绪线程队列,则系统线程逐个按次序绑定到就绪线程上,并将该线程转入运行线程队列;线程状态转为运行状态,随后控制权转入线程入口,同时输入触发此次运行的事件,线程运行;d. The system thread is blocked and waits on the ready thread queue. Once a thread enters the ready thread queue, the system threads are bound to the ready thread one by one in order, and the thread is transferred to the running thread queue; the thread state is changed to the running state , and then the control is transferred to the thread entry, and the event that triggers this operation is input at the same time, and the thread runs;
e、当线程对当前事件处理完成后,查看其事件接收区是否有其他事件存在,如果有,则该线程从运行线程队列转入就绪线程队列;如果没有,该线程退出运行线程队列,其状态转换成空闲状态;e. After the thread finishes processing the current event, check whether there are other events in its event receiving area. If so, the thread will be transferred from the running thread queue to the ready thread queue; if not, the thread will exit the running thread queue and its status transition to idle state;
f、在每次线程状态的切换时,都伴随着系统线程数量的重新计算,根据当前线程总数,就绪线程数,运行线程数,空闲线程数,系统线程数,计算出是否需要增加或是减少系统线程的数量;f. Every time the thread state is switched, it is accompanied by the recalculation of the number of system threads. According to the current total number of threads, the number of ready threads, the number of running threads, the number of idle threads, and the number of system threads, calculate whether it needs to be increased or decreased the number of system threads;
5、线程的退出;5. Thread exit;
线程的退出以完成线程数据的清除,线程标识的释放,并调整系统线程数量。The exit of the thread is to clear the thread data, release the thread ID, and adjust the number of system threads.
共享线程实现和调度方法的线程创建中,线程入口设置包括,确定一个唯一线程的线程标识、线程入口地址的定义及线程入口参数的指定。In the shared thread implementation and thread creation of the scheduling method, the setting of the thread entry includes determining the thread identifier of a unique thread, the definition of the thread entry address and the designation of the thread entry parameters.
共享线程实现和调度方法的线程激活中,线程的激活可以在线程创建的同时,也可以在线程创建后由调用者进行。In the thread activation of the shared thread implementation and scheduling method, the thread activation can be performed at the same time as the thread is created, or by the caller after the thread is created.
共享线程实现和调度方法的线程运行的触发事件可以是线程之间的消息、外界输入的信息或线程激活。The triggering event for thread execution of the shared thread implementation and scheduling method can be a message between threads, information input from the outside world or thread activation.
本发明提出的线程实现和调度方法应用于多线程系统中,具有以下有益效果:The thread implementation and scheduling method proposed by the present invention is applied in a multi-thread system, and has the following beneficial effects:
(1)线程结构数据位于用户空间,线程的操作(创建,切换,退出)不涉及任何的内核空间的访问,速度快。(1) The thread structure data is located in the user space, and the thread operation (creation, switching, exit) does not involve any access to the kernel space, and the speed is fast.
(2)线程数量不受到系统资源的限制,可以提供数量巨大的线程。(2) The number of threads is not limited by system resources, and a huge number of threads can be provided.
(3)只有运行状态的线程占用系统线程资源,并且线程在结束当前事件处理后会尽可能释放系统线程资源,使系统线程资源得到充分的利用。(3) Only running threads occupy the system thread resources, and the threads will release the system thread resources as much as possible after finishing the current event processing, so that the system thread resources can be fully utilized.
(4)在线程的生命周期中,多个线程共享一个系统线程,使得系统线程数量相比线程数大大减少,从而减少系统线程的切换时间,提高系统运行效率。(4) In the thread life cycle, multiple threads share one system thread, so that the number of system threads is greatly reduced compared with the number of threads, thereby reducing the switching time of system threads and improving the operating efficiency of the system.
附图说明Description of drawings
图1为本发明的线程控制块结构示意图;Fig. 1 is the structural representation of thread control block of the present invention;
图2为本发明的线程状态切换示意图;Fig. 2 is a schematic diagram of thread state switching of the present invention;
图3为本发明的线程调度示意图;Fig. 3 is a schematic diagram of thread scheduling of the present invention;
图4为本发明的线程运行和调度流程示意图。Fig. 4 is a schematic diagram of the thread running and scheduling flow in the present invention.
附图中a为空闲线程,b为就绪线程,c为运行线程,d为阻塞线程,e为系统线程。In the accompanying drawings, a is an idle thread, b is a ready thread, c is a running thread, d is a blocked thread, and e is a system thread.
具体实施方法Specific implementation method
具体的讲整个线程的实现和调度方法为:Specifically speaking, the implementation and scheduling method of the entire thread is:
1.线程的创建1. Thread creation
线程的创建主要完成线程控制块的设置和线程绑定,线程控制块的设置包括线程入口的设置(线程入口是线程被调度时执行代码的起始点,可以使用指向该起始点的地址表示),线程入口的设置就是将该地址保存在线程控制块中;事件接收区申请与初始化(事件接收区为一内存缓冲区,它的申请就是获取一块可用的内存空间,并将其中的内容设置为初始状态),这些工作完全在用户空间完成,不涉及任何内核空间的访问,因此效率是很高的。线程的绑定主要是根据当前线程使用状况,决定是否需要创建新的系统线程参与线程的调度。该操作对外提供相应的元语。The creation of thread mainly completes the setting of thread control block and thread binding. The setting of thread control block includes the setting of thread entry (thread entry is the starting point of code execution when the thread is scheduled, and can be represented by the address pointing to the starting point), The setting of the thread entry is to save the address in the thread control block; the application and initialization of the event receiving area (the event receiving area is a memory buffer, and its application is to obtain an available memory space, and set the content in it as the initial state), these tasks are completely done in user space, and do not involve any access to kernel space, so the efficiency is very high. Thread binding is mainly based on the current thread usage status to determine whether to create a new system thread to participate in thread scheduling. This operation provides the corresponding metalanguage externally.
2、线程的激活2. Thread activation
线程创建后处于初始状态,需要事件触发方可真正的工作,这种初始的触发称为线程的激活,线程在激活之前,不处理接收到的事件。线程的激活可以在线程创建的同时完成,也可以在线程创建后由调用者显式的进行。线程的激活是一次线程状态的切换操作(从初始状态切换至其他状态)。After the thread is created, it is in the initial state and needs to be triggered by an event to work. This initial trigger is called the activation of the thread. Before the thread is activated, the received event will not be processed. Thread activation can be done at the same time as the thread is created, or it can be done explicitly by the caller after the thread is created. Activation of a thread is a thread state switching operation (switching from an initial state to another state).
3、线程的运行3. Thread running
线程的运行是由事件触发的,事件的种类可以是多种多样的,主要包括线程之间的消息,外界输入等,上面提到的线程激活也是一种事件。当有事件触发后,线程转入运行状态,并与系统线程绑定,对当前的事件处理结束后,重新转入空闲状态,并与系统线程分离。The running of threads is triggered by events, and the types of events can be various, mainly including messages between threads, external input, etc. The thread activation mentioned above is also a kind of event. When an event is triggered, the thread enters the running state and is bound to the system thread. After processing the current event, it returns to the idle state and separates from the system thread.
4、线程的调度4. Thread scheduling
线程的调度是本方法的主要部分,线程的调度主要完成如下几个功能:线程状态的切换,线程就绪线程队列的管理,线程运行线程队列的管理以及相应的入队出队操作。本方法提出的线程调度并不是由一个独立的实体完成,线程系统中所有的运行线程共同完成整个线程机制的调度工作。具体工作如下:Thread scheduling is the main part of this method. Thread scheduling mainly completes the following functions: thread state switching, thread ready thread queue management, thread running thread queue management, and corresponding enqueue and dequeue operations. The thread scheduling proposed by this method is not completed by an independent entity, and all running threads in the thread system jointly complete the scheduling work of the entire thread mechanism. The specific work is as follows:
(1)线程系统维护数据结构:就绪线程队列数据结构和运行线程队列数据结构;(1) Thread system maintains data structures: ready thread queue data structure and running thread queue data structure;
这两个数据结构的维护完全是数据的操作,包括向队列或池中增加一个数据,The maintenance of these two data structures is completely a data operation, including adding a data to the queue or pool,
或从队列和池中取出一个数据,其中队列维护进入队列数据的次序,采用先进先出的原则,而池则不需要维护这样的次序。Or take out a piece of data from the queue and the pool, where the queue maintains the order of the data entering the queue, using the first-in first-out principle, while the pool does not need to maintain such an order.
(2)每一个线程可由主线程(进程内固有的系统线程)和其他线程创建线程的创建是通过线程创建元语实现的。(2) Each thread can be created by the main thread (inherent system thread in the process) and other threads. The creation of threads is realized through thread creation primitives.
(3)某个空闲线程有事件触发时,事件的发出方在发送事件(将事件放入接收线程的事件接收区)的同时,将接收线程从空闲状态转入就绪状态,并将该线程放入就绪线程队列。(3) When an event is triggered by an idle thread, the sender of the event will transfer the receiving thread from the idle state to the ready state while sending the event (putting the event into the event receiving area of the receiving thread), and put the thread in the ready state. into the ready thread queue.
(4)系统线程阻塞等待在就绪线程队列上,一旦有线程进入就绪线程队列,(4) The system thread blocks and waits on the ready thread queue. Once a thread enters the ready thread queue,
则系统线程逐个按次序绑定到就绪线程上,并将该线程转入运行线程队列,线程状态转换为运行状态,随后控制权转入线程入口,同时输入触发此次运行的事件,线程运行(对事件的处理)。Then the system threads are bound to the ready thread one by one in order, and the thread is transferred to the running thread queue, the thread state is converted to the running state, and then the control right is transferred to the thread entry, and the event that triggers this operation is input at the same time, and the thread runs ( handling of events).
(5)当线程对当前事件处理完成后,查看其事件接收区是否有其他事件存在,如果有,则该线程从运行线程队列转入就绪线程队列;如果没有,该线程退出运行线程队列,其状态转换成空闲状态。(5) After the thread finishes processing the current event, check whether there are other events in its event receiving area. If there is, the thread is transferred from the running thread queue to the ready thread queue; if not, the thread exits the running thread queue, and its state transitions to the idle state.
(6)在每次线程状态的切换时,都伴随着系统线程数量的重新计算,根据当前线程总数,就绪线程数,运行线程数,空闲线程数,系统线程数,计算出是否需要增加或是减少系统线程的数量。(6) When each thread state is switched, it is accompanied by the recalculation of the number of system threads. According to the current total number of threads, the number of ready threads, the number of running threads, the number of idle threads, and the number of system threads, calculate whether it needs to be increased or not. Reduce the number of system threads.
5、线程的退出5. Thread exit
线程的退出完成线程数据的清除,线程标识的释放,并调整系统线程数量。The exit of the thread completes the clearing of the thread data, the release of the thread ID, and adjusts the number of system threads.
如图1所示,显示了线程控制块的结构,包括线程标识,线程入口地址,线程入口参数,事件接收区地址,线程状态,线程属性以及其他线程数据;各部分说明如下:As shown in Figure 1, it shows the structure of the thread control block, including thread identification, thread entry address, thread entry parameters, event receiving area address, thread status, thread attributes and other thread data; each part is described as follows:
线程标识用于唯一的确定一个线程,在线程入队操作可以代替线程实体,在线程间消息发送时可以用于寻址。线程标识必须在进程内唯一,可以通过统一的分配机制实现,线程退出后,标识释放允许重复使用。The thread ID is used to uniquely determine a thread, and can replace the thread entity in the thread enqueue operation, and can be used for addressing when sending messages between threads. The thread ID must be unique within the process, which can be realized through a unified allocation mechanism. After the thread exits, the ID release allows reuse.
线程入口地址用于在线程运行时控制权的传入,入口的形式可以自行定义。The thread entry address is used to pass in the control right when the thread is running, and the form of the entry can be defined by yourself.
线程入口参数用于传入线程在创建时指定的参数。The thread entry parameter is used to pass in the parameters specified when the thread is created.
事件接收区地址用于存放触发线程运行的事件,该接收区维护事件到达的先后次序,保证先达事件先处理。The address of the event receiving area is used to store the events that trigger the thread to run. The receiving area maintains the order of event arrival to ensure that the events that arrive first are processed first.
线程状态用于指定线程生命周期的不同阶段的行为,状态是可循环的,可切换的,具体描述见图2的说明。The thread state is used to specify the behavior of different stages of the thread life cycle. The state is cyclic and switchable. See the description in Figure 2 for details.
线程的属性用于描述线程的一些固有性质,由线程创建时指定,在线程运行期间可以修改部分属性。The attributes of the thread are used to describe some inherent properties of the thread, which are specified when the thread is created, and some attributes can be modified during the running of the thread.
线程的其他数据,这部分可以根据具体的实现自行处理。Other data of the thread, this part can be processed by itself according to the specific implementation.
图2描述了线程在整个生命期拥有的各种状态及其转换。在线程的整个生命期中,线程的状态包括:初始状态,空闲状态,就绪状态,运行状态,阻塞状态,关闭状态。Figure 2 describes the various states and transitions that a thread has throughout its lifetime. Throughout the life of the thread, the state of the thread includes: initial state, idle state, ready state, running state, blocked state, and closed state.
初始状态:线程创建后即处于该状态,处于初始状态时,线程不被运行,只有线程激活操作才可以使线程离开初始状态。当激活时,线程的事件接收区内没有事件,状态转换为空闲状态;否则,当激活,并且线程的事件接收区有事件时,转换为就绪状态。Initial state: The thread is in this state after it is created. In the initial state, the thread is not run, and only the thread activation operation can make the thread leave the initial state. When activated, there is no event in the event receiving area of the thread, and the state transitions to the idle state; otherwise, when activated and there is an event in the event receiving area of the thread, it transitions to the ready state.
空闲状态:该状态表示线程的事件接收区内没有事件,该状态在有事件触发下转换为就绪状态;在有外部线程终止操作时,转换为关闭状态。Idle state: This state indicates that there is no event in the event receiving area of the thread, and this state is converted to the ready state when an event is triggered; when an external thread terminates the operation, it is converted to the closed state.
就绪状态:该状态表示线程在激活后,有事件触发,线程进入就绪线程队列等待运行。当线程到达队列头,并有系统线程绑定,则状态转换为运行状态;当在等待运行期间有外部线程终止操作,则转入关闭状态。Ready state: This state means that after the thread is activated, an event is triggered, and the thread enters the ready thread queue to wait to run. When the thread reaches the head of the queue and is bound by a system thread, the state changes to the running state; when an external thread terminates the operation while waiting to run, it turns to the closed state.
运行状态:当线程被系统线程绑定后,则进入运行状态。在运行结束后,如果没有事件处理,则转入空闲状态;否则转入就绪状态。Running state: When the thread is bound by the system thread, it enters the running state. After running, if there is no event processing, it will go to the idle state; otherwise, it will go to the ready state.
阻塞状态:当线程在运行期间调用阻塞操作时,将状态变换成阻塞状态,阻塞结束后,会继续进入运行状态,除非线程自行退出或是有外部终止,这将会使线程切换至关闭状态。Blocking state: When a thread calls a blocking operation during running, the state is changed to a blocking state. After the blocking is over, it will continue to enter the running state, unless the thread exits by itself or is terminated externally, which will switch the thread to the closed state.
关闭状态:当线程在生命期内被终止或是退出,则切换至关闭状态。Closed state: When the thread is terminated or exited within the lifetime, it will switch to the closed state.
图3显示了线程的调度和运行过程。具体如下:Figure 3 shows the thread scheduling and running process. details as follows:
·线程创建时,处于初始状态,在激活后线程进入调度流程。如果当前没有事件触发,线程始终处于空闲状态(如图3中a),与系统线程相分离(如图3中e)。When the thread is created, it is in the initial state, and the thread enters the scheduling process after activation. If no event is currently triggered, the thread is always in an idle state (a in Fig. 3 ), and is separated from the system thread (e in Fig. 3 ).
·当有事件触发某个空闲线程时,该空闲线程被挂入就绪线程队列(如图3中b),排队等待绑定。·When an event triggers a certain idle thread, the idle thread is hung into the ready thread queue (b in Fig. 3) and queued up to wait for binding.
·有一个或多个系统线程阻塞在就绪线程队列上(如图3中d),当就绪线程队列中存在线程时,唤醒一个系统线程与其绑定,将其挂入运行线程队列,线程运行(如图3中c)。There are one or more system threads blocked on the ready thread queue (d in Figure 3), when there are threads in the ready thread queue, wake up a system thread bound to it, hang it into the running thread queue, and the thread runs ( As shown in c) in Figure 3.
·当线程处理完当前事件后返回,将其从运行线程队列中清除,根据其是否存在后续事件,决定切换其状态至空闲还是就绪,并与系统线程分离。When the thread returns after processing the current event, it is cleared from the running thread queue. According to whether there is a follow-up event, it decides to switch its state to idle or ready, and separates from the system thread.
·如果运行中的线程进行了阻塞调用,则其将被标记为阻塞,该标记在其被外部终止等操作中使用。· If a running thread makes a blocking call, it will be marked as blocked, which is used in operations such as its being terminated externally.
·如果运行中的线程要求退出或是被外部终止,与其绑定的系统线程将根据线程的运行情况,实施分离和终止操作。·If the running thread requests to exit or is terminated externally, the system thread bound to it will implement separation and termination operations according to the running status of the thread.
通过线程调度如图3所述,可以清楚的看到线程是如何运行的。首先,线程的调度是在每一个状态切换时进行,在线程运行期间是不会进行调度的,因此线程的调度是在用户级别进行的,不涉及到系统线程的切换,因此这种调度很安全。第二,线程的调度与事件的触发有着密切的关系,可以说在线程的调度是通过事件驱动的。第三,线程的调度涉及到线程与系统线程的绑定与分离,这个过程是动态进行的。Through the thread scheduling as shown in Figure 3, you can clearly see how the threads run. First of all, thread scheduling is performed at each state switch, and it will not be scheduled during thread running. Therefore, thread scheduling is performed at the user level and does not involve system thread switching, so this scheduling is very safe. . Second, the scheduling of threads is closely related to the triggering of events. It can be said that the scheduling of threads is driven by events. Third, thread scheduling involves the binding and separation of threads and system threads, and this process is carried out dynamically.
Claims (4)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CNB011390808A CN1328877C (en) | 2001-12-03 | 2001-12-03 | Sharing route realizing and sheduling method |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CNB011390808A CN1328877C (en) | 2001-12-03 | 2001-12-03 | Sharing route realizing and sheduling method |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN1423456A CN1423456A (en) | 2003-06-11 |
| CN1328877C true CN1328877C (en) | 2007-07-25 |
Family
ID=4675009
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CNB011390808A Expired - Fee Related CN1328877C (en) | 2001-12-03 | 2001-12-03 | Sharing route realizing and sheduling method |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN1328877C (en) |
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN109254834A (en) * | 2017-07-13 | 2019-01-22 | 普天信息技术有限公司 | A kind of multithreading starting synchronous method |
Families Citing this family (15)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US7152152B2 (en) * | 2004-01-22 | 2006-12-19 | International Business Machines Corporation | Method of avoiding flush due to store queue full in a high frequency system with a stall mechanism and no reject mechanism |
| CN101057476B (en) * | 2004-08-17 | 2014-01-08 | 肖分析有限公司 | Techniques for delivering personalized content with a real-time routing network |
| CN101346692B (en) * | 2005-12-29 | 2011-05-04 | 英特尔公司 | High-performance queue implementing of multiprocessor system |
| CN101291233B (en) | 2007-04-20 | 2011-04-20 | 华为技术有限公司 | Method and system realizing event detection |
| CN101299677B (en) * | 2008-04-30 | 2010-12-01 | 中兴通讯股份有限公司 | A method for multiple processes to share the same service process |
| CN101561764B (en) * | 2009-05-18 | 2012-05-23 | 华为技术有限公司 | Patching method and patching device under multi-core environment |
| CN103092682B (en) * | 2011-10-28 | 2016-09-28 | 浙江大华技术股份有限公司 | Asynchronous network applications program processing method |
| CN102981901A (en) * | 2012-11-19 | 2013-03-20 | 北京思特奇信息技术股份有限公司 | Method and device for processing connection request |
| CN103179294B (en) * | 2013-03-12 | 2015-04-08 | 厦门亿联网络技术股份有限公司 | Method for preventing task congestion in VOIP (voice over internet protocols) phone through thread pool |
| JP6387747B2 (en) * | 2013-09-27 | 2018-09-12 | 日本電気株式会社 | Information processing apparatus, failure avoidance method, and computer program |
| US9515901B2 (en) * | 2013-10-18 | 2016-12-06 | AppDynamics, Inc. | Automatic asynchronous handoff identification |
| CN108052392B (en) * | 2017-12-26 | 2020-12-25 | 成都质数斯达克科技有限公司 | Service processing method and device based on block chain |
| CN110119267B (en) * | 2019-05-14 | 2020-06-02 | 重庆八戒电子商务有限公司 | Method and device for improving performance of relation programming |
| CN112579515B (en) * | 2019-09-27 | 2023-03-24 | Oppo广东移动通信有限公司 | Thread message processing method and related product |
| CN115225633B (en) * | 2022-06-24 | 2024-04-12 | 浪潮软件集团有限公司 | State machine state transition method and system based on opposite-end network signal |
Citations (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US6058460A (en) * | 1996-06-28 | 2000-05-02 | Sun Microsystems, Inc. | Memory allocation in a multithreaded environment |
| US6223204B1 (en) * | 1996-12-18 | 2001-04-24 | Sun Microsystems, Inc. | User level adaptive thread blocking |
-
2001
- 2001-12-03 CN CNB011390808A patent/CN1328877C/en not_active Expired - Fee Related
Patent Citations (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US6058460A (en) * | 1996-06-28 | 2000-05-02 | Sun Microsystems, Inc. | Memory allocation in a multithreaded environment |
| US6223204B1 (en) * | 1996-12-18 | 2001-04-24 | Sun Microsystems, Inc. | User level adaptive thread blocking |
Non-Patent Citations (3)
| Title |
|---|
| 多线程技术 李新明 李艺,小型微型计算机系统,第19卷第2期 1998 * |
| 多线程的实现方法 张利霞,河南师范大学学报,第29卷第2期 2001 * |
| 多线程的实现方法 张利霞,河南师范大学学报,第29卷第2期 2001;多线程技术 李新明 李艺,小型微型计算机系统,第19卷第2期 1998 * |
Cited By (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN109254834A (en) * | 2017-07-13 | 2019-01-22 | 普天信息技术有限公司 | A kind of multithreading starting synchronous method |
| CN109254834B (en) * | 2017-07-13 | 2021-05-14 | 普天信息技术有限公司 | Multithreading starting synchronization method |
Also Published As
| Publication number | Publication date |
|---|---|
| CN1423456A (en) | 2003-06-11 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN1328877C (en) | Sharing route realizing and sheduling method | |
| JP3872690B2 (en) | System and method for providing a pool of reusable threads for performing queued work items | |
| US7594234B1 (en) | Adaptive spin-then-block mutual exclusion in multi-threaded processing | |
| US7082519B2 (en) | System and method for instruction level multithreading scheduling in a embedded processor | |
| KR100936601B1 (en) | Multiprocessor system | |
| US20050081200A1 (en) | Data processing system having multiple processors, a task scheduler for a data processing system having multiple processors and a corresponding method for task scheduling | |
| US20040172631A1 (en) | Concurrent-multitasking processor | |
| US20050015768A1 (en) | System and method for providing hardware-assisted task scheduling | |
| US8321874B2 (en) | Intelligent context migration for user mode scheduling | |
| US20020103847A1 (en) | Efficient mechanism for inter-thread communication within a multi-threaded computer system | |
| US20120054769A1 (en) | Dividing a computer job into micro-jobs | |
| CN102375761A (en) | Business management method, device and equipment | |
| WO2023246044A1 (en) | Scheduling method and apparatus, chip, electronic device, and storage medium | |
| CN115167996A (en) | Scheduling method and device, chip, electronic device and storage medium | |
| CN1801101A (en) | Thread implementation and thread state switching method in Java operation system | |
| JPH06250853A (en) | Management method and system for process scheduling | |
| US20050066149A1 (en) | Method and system for multithreaded processing using errands | |
| CN112346835B (en) | Scheduling processing method and system based on coroutine | |
| CN111597044A (en) | Task scheduling method and device, storage medium and electronic equipment | |
| CN111538535A (en) | CPU instruction processing method, controller and central processing unit | |
| CN107589993A (en) | A kind of dynamic priority scheduling algorithm based on linux real time operating systems | |
| KR101377195B1 (en) | Computer micro-jobs | |
| WO2004061663A2 (en) | System and method for providing hardware-assisted task scheduling | |
| CN100340976C (en) | Method and apparatus for realizing computer multiple thread control | |
| CN120762840A (en) | An efficient collaborative task scheduling method for embedded systems based on RSIC-v architecture |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| C06 | Publication | ||
| PB01 | Publication | ||
| ASS | Succession or assignment of patent right |
Owner name: SHENZHENG CITY ZTE CO., LTD. Free format text: FORMER OWNER: SHENZHENG CITY ZTE CO., LTD. SHANGHAI SECOND INSTITUTE Effective date: 20030723 |
|
| C41 | Transfer of patent application or patent right or utility model | ||
| TA01 | Transfer of patent application right |
Effective date of registration: 20030723 Applicant after: Zhongxing Communication Co., Ltd., Shenzhen City Applicant before: Shanghai Inst. of No.2, Zhongxing Communication Co., Ltd., Shenzhen City |
|
| C10 | Entry into substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| C14 | Grant of patent or utility model | ||
| GR01 | Patent grant | ||
| ASS | Succession or assignment of patent right |
Owner name: STATE GRID BEIJING ELECTRIC POWER COMPANY CHINA TE Effective date: 20140129 Owner name: BEIJING POWER ECONOMIC RESEARCH INSTITUTE Free format text: FORMER OWNER: ZTE CORPORATION Effective date: 20140129 |
|
| COR | Change of bibliographic data |
Free format text: CORRECT: ADDRESS; FROM: 518057 SHENZHEN, GUANGDONG PROVINCE TO: 100055 XICHENG, BEIJING |
|
| TR01 | Transfer of patent right |
Effective date of registration: 20140129 Address after: 100055 No. 15 West Street, Guanganmen station, Beijing, Xicheng District Patentee after: State Power Economic Research Institute Patentee after: State Grid Beijing Electric Power Company Patentee after: CHINA TECHNOLOGY EXCHANGE CO., LTD. Address before: 518057 Department of law, Zhongxing building, South Science and technology road, Nanshan District hi tech Industrial Park, Shenzhen Patentee before: ZTE Corporation |
|
| TR01 | Transfer of patent right | ||
| CF01 | Termination of patent right due to non-payment of annual fee |
Granted publication date: 20070725 Termination date: 20141203 |
|
| CF01 | Termination of patent right due to non-payment of annual fee |