Книга: Programming with POSIX® Threads

9.2 POSIX1003.1c-1995 limits

9.2 POSIX1003.1c-1995 limits

The Pthreads standard allows you to determine the run-time limits of the system that may affect your application, for example, how many threads you can create, by defining a set of macros, which are shown in Table 9.2. Any implementation of Pthreads must inform you of its limits, by three means:

• By making a formal statement in the POSIX Conformance Document. You can use this information to help design your application to work on specific systems.

• By defining compile-time symbolic constants in the <limits.h> header file. The symbolic constant may be omitted from <limits.h> when the limit is at least as large as the required minimum, but cannot be determined at compile time, for example, if it depends on available memory space. You can test for these symbolic constants using #ifdef or #ifndef preprocessor conditionals.

• By returning a positive nonzero value when the sysconf function is called with the associated sysconf symbol.

You might, for example, design your application to rely on no more than 64 threads, if the conformance documents showed that three out of the four systems

Run-time invariant values,  Description
sysconf symbol name
PTHREAD_DESTRUCTOR_ITERATIONS _SC_THREAD_DESTRUCTOR_ITERATIONS Maximum number of attempts to destroy a thread's thread-specific data on termination (must be at least 4).
PTHREAD_KEYS_MAX _SC_THREAD_KEYS_MAX Maximum number of thread-specific data keys available per process (must be at least 128).
PTHREAD_STACK_MIN _SC_THREAD_STACK_MIN Minimum supported stack size for a thread.
PTHREAD_THREADS_MAX _SC_THREAD_THREADS_MAX Maximum number of threads supported per process (must be at least 64).
TABLE 9.2 POSIX 1003.1 c-1995 limits

you wish to support do not support additional threads. Or you might prefer to write conditional code that relies on the value of the PTHREAD_THREADS_MAX symbolic constant (if defined) or call sysconf to determine the limit at run time.

Оглавление книги


Генерация: 1.214. Запросов К БД/Cache: 3 / 0
поделиться
Вверх Вниз