ct_set_countdown

The ct_set_countdown function adjusts the strength of the prioritization of threads within the scheduler.

Prototype:

void ct_set_countdown( unsigned n );

Parameters:

n
The number of threads to run before scrunching the queues. A value of zero, not being sensible, will be silently changed to one.

Return Value:

The previous value of the number of threads between scrunches.

Discussion:

In order to ensure that even a low-priority thread will run eventually, the scheduler periodically raises the priority of all runnable threads that are not already enqueued at the highest priority. This operation, called "scrunching the queues", is described in more detail elsewhere.

By default, the scheduler scrunches the queues every time it has run a fixed number of threads, defined in the ct.h header as CT_DEFAULT_COUNTDOWN. This default is arbitrary, and may not be appropriate for a given application.

The ct_set_countdown function enables an application to specify how many threads to run between scrunching operations.

This parameter governs the strength of prioritization among threads. For example, with the countdown set to 8 threads per scrunch (the default), threads with a priority of zero will run about 8 times as frequently as those with a priority of one, about 64 times as frequently as those with a priority of two, and so forth.

Setting the countdown to a higher value will increase the difference in frequency among threads at different priorities. Conversely, setting it to a lower value will reduce the difference. Thus the ct_set_countdown function is one of the available tools for tuning the scheduler.

If the application saves the return value it can restore the previous value of the countdown.

Restrictions:

An application may call ct_set_countdown() at any time, though it is not useful for it to do so after the scheduler has terminated.
Home