RU/2: Форум. Общение пользователей и разработчиков OS/2 (eCS). : Multithreading (III)


Список сообщений | Написать новое | Ответить на сообщение | Домой Поиск:
Предыдущее сообщение | Следующее сообщение
From : ???
To : All
Subj : Multithreading (III)

The THREADS parameter in Config.sys

The task management of OS/2 is divided in to three seperate entities:

* Threads

* Processes

* Sessions

A thread is the only unit to get its own time slice of the CPU. All threads belonging to
a process are contained within the process, and each thread has its own stack and
registers. Each thread consumes with its stack space 4096 (4k) bytes of the resident
memory.

There is a systemwide limit of 4096 threads(OS/2 4.x); however, Config.sys contrains a
THREADS parameter that is usually set to a significantly smaller number - 64 is the
default(Source: OS/2 Warp Version 4 Certification Handbook, Oct. 1996, SG24-4869-00,
p. 1061). The base operating system uses approximatlely 40 threads.

Typically, a thread should have one distinct function; for example, file I/O, asynchronous
communication, or heavy number crunching. Each thread has a thread identifier - a TID.
Each thread has also a priority(later lession shows more about this priority). The higher
the priority, the more time slices are given to the thread. A thread is much quicker to
create than a process or sessions and has less system overhead.

All threads within a process run in the same virtual address space; therefore, global
resources, such as file handles, and global variables are accessible from all threads
in the process. Threads can be created through an OS/2 API like DosCreateThread, with
the first thread created automatically by the operating sytem. When a thread is created
it is assigned the same priority class as the thread that created it(i.e. a thread can create
another thread).

A process is a collection of threads and resources that are owned by those threads.
Each process occupies a unique address space in memory that cannot be addressed by
other processes in the system. Two processes can access the same area in memory only
by using 'shared memory'. A process also contains file handles, semaphores, and other
resources. All processes contain at least one thread, the 'main thread'.

A process also contains a unique identifier - a PID(Process IDentifier). A process contains
its own set of memory pages that can be swapped in and out (called 'paging') as the
kernel switches from one process to the other. A process can create other processes;
however, this must be the same session type. For instance, a full-screen process can
only create other full-screen processes.

The 5 types of processes are:

1. OS/2 Full screen
2. OS/2 windowed
3. DOS Full screen
4. DOS windowed
5. Presentation Manager(PM)

A session is similar to a process except a session also contains the ownership of the
mouse, keyboard, and video(screen). A session can contain either one process or multiple processes.

The task list(accesed by CRT-ESC) contains a list of all running sessions. When a
process or a session creates a new session using the OS/2 API DosStartSession, the
keyboard, screen, and mouse are responsive only to the session in the foreground.
The session chosen as the background can gain control of the three resources only by
switching to the foreground.


Boosts from the Scheduler
**************************

The OS/2 Scheduler runs on a round-robin type of disbursement of CPU time. The
Scheduler works only with threads, not with processes or sessions. Threads have
4 different priority levels:

1. time-critical
2. server class or fixed high
3. regular
4. idle-time

The first threads to run are the time-critical threads. All time-critical threads will run
until there are no more time-critical threads waitung to be run.
After all time-critical threads are finished, the server-class threads are to run. After
server-class, the regular class of threads are run.
After the regular class of threads are run, idle-time therads are run.

Within each class of priorities are 32 sublevels.

A thread that is not running is called a 'blocked' thread(more in lession "Process/Thread
Model").

The OS/2 Scheduler works a lot around with thread priorities. Threads are given "boosts"
by the scheduler to make OS/2 multitasking smarter. Three types of artifical priority
boosts are given to threads:

1. Foreground boosts
2. I/O boosts
3. Starvation boosts

The foreground boost is given to the user interface thread of the process that is in
foreground. This is usually the main thread. The foreground process is the process with
which the user is currently interacting. This makes the system respond quickly when the
user clicks a mouse button or types in characters at a keyboard. This boost is a full
boost in priority. Also, a Presentation Manager thread has a boost applied to it while
it is processing a message.

An I/O boost is given after an I/O operation is completed. An I/O boost does not change
a thread's priority but will bump it up to level 31(the highest level of 32 stages) within
its own priority class.

A starvation boost is given to a thread in the regular class that has not been able to
run. The MAXWAIT parameter in Config.sys is used to define how long, in seconds, a
thread must not(!) run before it is given a starvation boost. This duration for waiting is
also called the "ready-to-run state". The default value is 3 seconds.

The time slices for threads that are given a starvation boost or an I/O boost are different
from a normal time slice. Because of the tinkering the scheduler does with their priorities,
they do not get run as long as a nonadjusted thread would run.

The length of time for the 'short' and normal time slices is controlled by the TIMESLICE
parameter in Config.sys. The first value repressents the 'short' time slice lenght; the
default amount of time is set to 32 ms(milliseconds). The second value represents the
normal slice lenght; the default amount of time is set to 65 536 ms.











Sun 21 Dec 2003 17:53 Mozilla/4.61 [en] (OS/2; U)




Programmed by Dmitri Maximovich, Dmitry I. Platonoff, Eugen Kuleshov.
25.09.99 (c) 1999, RU/2. All rights reserved.
Rewritten by Dmitry Ban. All rights ignored.