Exercise 4 - Multiple Threads

This exercise demonstrates that an OS/2 program can start a very large number of threads (up to a maximum of 4096, minus those threads the system has already started). The program makes use of C Set/2 _beginthread function.

In this exercise, the student is required to run the memory lab program:

           MEMLAB4.exe

Syntax: MEMLAB4 <number of threads>

If number of threads is not entered, ten (10) is assumed.

This program does the following:

  • Starts the specified number of threads.

    Each thread is very simple; it merely issues a DosSleep() function call and an occasional write to screen. This is in order that all threads may start within a reasonable time frame.

    For practical reasons, do not try to start more than 200 threads.

  • When all the threads are started, the program waits for keyboard input.

    At this time we suggest you issue the PSTAT command from an OS/2 Command Prompt. Use the "\C" option. This displays a list of all processes and threads open in the system. You can also see the number of threads in use for system functions.

  • When the program receives a keystroke, it sets a flag to request the threads to terminate. When all started threads have terminated, the program exits.

    The program listing is shown in Source Code MEMLAB4.C.

    If you are able to do the exercise Please do so now. If not, refer to the following explanation.

    The following error message may be generated:

    DosCreateThread error = 164.

    This typically occurs when the maximum allowed number of threads specified in CONFIG.SYS is less than the number of threads requested.

    Note: Remember that the specified number of threads in the CONFIG.SYS file includes threads used by the operating system. This amounts to approximately 22 threads.

    If the required number of threads cannot be started, check the CONFIG.SYS file. This file contains a specification for the maximum number of threads allowed in the system. Increase the threads command to: THREADS = 4095, and re-IPL the system.


    [Back: Sample Input File for MEMLAB3.EXE]
    [Next: Expected Results From Exercise 4]