StackThreads/MP: version 0.77 User's Guide
A worker refers to an underlying OS-thread such as a thread of Solaris
Thread library or Pthreads library. Normally, StackThreads/MP program
creates a fixed number of workers at program initialization and they
share threads created by st_main
, directly or indirectly. In this
simple use of StackThreads/MP, you do not have to understand the
following procedures and do not even have to know the notion of workers
or worker groups.
StackThreads/MP allows other ways to access the provided multithreading
facility. Specifically, you can dynamically create another group of
workers and add workers to an existing group. Creating a group of
workers dynamically is useful in several circumstances. First, when you
want to have multiple groups of workers and to keep them isolated;
threads are shared only among workers within a single group and threads
are never migrated from one group to another. Second, creating a group
of workers at runtime allows you to increase or decrease the number of
OS-threads (the number of threads visible to OS) according to the
application's need. In particular, an application can spend most of the
time with a single thread and create a group of workers to perform a
compute-intensive task in parallel. When the task is finished, all
workers will die and the application goes back to its single-threaded
state. Actually, such an application could be built without dynamically
creating worker groups, if you do not care about the fact that many idle
threads may consume CPU time when the application has no parallelism.
Third, unlike other StackThreads/MP procedures, the procedure that
creates a worker group (stf_create_worker_group
) can be called from
programs that is not compiled by stgcc
. Thus, it can be used as a
callback from library whose source is not available.