In wide-ranging discussions,
the thread subcommittee asked and answered
a number of questions about how to introduce threads into C++.
Shall threads be explicit? |
Yes. |
Are threads coarse-grained? |
Yes. |
Is thread creation dynamic? |
Yes. |
If so, is it program controlled? |
Yes. |
Is work explicitly asigned to threads? |
Yes. |
Can one call exit only from the master thread? |
Yes, calling exit from a non-master thread induces an abort. |
What happens when exit is called while threads are detached? |
The result is implementation-defined. |
Is there a join operation? |
Yes. |
Are exceptions propogated through the join? |
Yes, otherwise they become unmanagable.
This propogation requires syntax or library ABI magic.
|
Should there be a join any or join all? |
Not in the base layer, leave it to higher layers. |
How are thread objects allocated? |
Dynamically, on the heap.
Thread objects on the stack are problematic
if an exception deletes the object,
better perhaps is dynamic allocation of the exception object. |
May threads be detached? |
Yes, it means there will be no join operation
and the thread object may delete itself
on return from the thread function. |
Does the master construct all globals variables? |
Maybe. The issue is a dlopen from a non-master thread
and the subsequent initialization of globals. |
Shall we require dlopen only from a master thread? |
No, this inhibits MT-hot libraries. |
Shall the implementation serialize all dlopens? |
Leave this implementation-defined. |
Shall we prohibit calling dlopen while holding a lock? |
No, this approach violates encapsulation in the library. |
Are recursive dlopens defined on different libries? |
Yes. |
Must non-recursive dlopens be serialized by user code? |
Maybe. |
Is communication via message? |
No, use MPI. |
Is communication via shared memory? |
Yes. |
Is synchronization via locks? |
Yes. |
If so, events or condition variables? |
Condition variables. They are much easier to use. |
Can threads synchronize between processes? |
Make possible, but not defined. |
Can threads synchronize with system threads? |
Yes. |
Can threads obtain handles on system threads? |
Yes, for scheduling. |
Are static-duration variables synchronizable? |
Yes. |
Are static-duration variables explicitly synchronized,
e.g. __synchronized keyword? |
Maybe. The issue is that it might be better
if they were all implicitly synchronized. |
Are locks in a library? |
Yes, there is a substantial variety. |
Is progress guaranteed? |
No. |
Are scheudling hints available? |
Maybe. Revisit this issue. |
Can one call terminate/abort anywhere? |
Yes, and terminate immediately. |
Can a thread cancel itself? |
Maybe. |
Can a thread cancel other threads synchronously? |
Maybe. |
Can a thread cancel other threads asynchronously? |
No, this does terrible damage to code generation. |
Can a thread suspend itself? |
No. |
Can a thread suspend others? |
No. |
Can a thread yield itself? |
Maybe. |
Can a thread yield other threads? |
No. |