进程与线程
进程由地址空间(address space),目标句柄(object handles),一条以上可执行的线程(threads)。线程多用于响应中断,或用来同步事件(handle asynchronous process-related events in thread context)。RTSS的进程与线程函数与Win32下的很相似。但是RTSS和Win32下的进程或者线程仅能在自己的环境中运行,不能相互访问。(RTSS and Win32 processes and threads can access processes and threads only within their own environment.,原文中是这样一句话,不知道自己理解的是否正确,但是就现实来看,Win32进程和RTSS进程之间可以通过共享内存来实现数据交换,那么这种情况就和文档中所描述的是矛盾的,以后有进一步理解后可以对这段东西进行修正)。
Win32进程与RTSS进程之间的关系可以用以下一张图来进行表述:
以下描述会大量饮用英文原文,对于重要的地方会用汉语进行注解
RTSS环境下的进程:
A process running in the RTSS environment consists of a set of handles to objects, process address space,at least one thread, andan executable(这个executable应该指一段可执行程序). When a process is created, RTSS performs the following tasks:
-
Loads the executable as a driver
-
Allocates process heap from the non-paged pool
-
Creates the primary thread
A process can be started by either one of these methods:
-
Loading it as a device driver during system boot (using the RTSSrun /b utility)
-
Running the RTSS executable from the command line
-
Starting the RTSS process from Win32 applications(这种方案是最实用,最常用的方案)
A process exits under one of these conditions:
-
The last thread has exited(这种情况我也遇到过,当主进程关闭时,所有的定时器进程也就关闭了)
-
One thread calls ExitProcess
-
The process is killed with the RTSSkill utility or the RTSS Task Manager(开始->Adrence->RTX->Tools->Rtss Task Managers)
The maximum number of processes that can exist concurrently in the RTSS environment is equal to the number of RTSS process slots in the registry (the default is 10).
其设置的位置如下图所示:
Win32环境下的进程:
A process running in the Win32 environment starts interacting with RTX when it makes an RTAPI call. RTX then may allocate resources for this process, alter its priorities, and perform other operations related to its Win32 process status. The number of Win32 processes that can interact with RTX is dynamic; it depends on your system's configuration and resources.
Using Threads
The CreateThread function createseither an RTSS or a Win32 thread, depending on the current execution environment of the process. You can specify the stack size of subsequently created threads of that process usingCreateThread. The returned handle and thread ID are valid only in theCreateThread caller's environment. For instance, a Win32 process cannot manipulate the priority of an RTSS thread because the handle for the thread is valid only in the RTSS environment. You can, however, use the RTX Interprocess Communication (IPC) mechanisms (such asmutex objects,semaphores, events, andshared memory) tosynchronize and com