Possible language changes

Doug Lea dl at cs.oswego.edu
Thu Mar 3 17:41:00 GMT 2005


Thanks very much! Hopefully the people on this list who
know more about C++ can help refine this, but here are a few initial
questions..

 > class Thread

>    thread_t spawn (void * (*func) (void *),
>                    void *arg = 0,
>                    Thread_Params *thread_parameters = 0);

1. Is there a good reason for separating thread_t and Thread?
    It would be nicer to say "Thread* t = new Thread(...)
    rather than thread_t t = Thread::spawn(...).

2. How burdensome would it be to require a little closure object
    instead of function pointer? Something like Java Runnable,
    although it would be better to use something like (j2SE5)
    Callable that can take arg, return result, and report exception.

3. Are there any spec tricks that would allow Thread_Params to
    be partially implementation defined? Like to have a
    required basic base class, and then an optional
     PThread_Params sublass etc?

>              
>   /**
>    * Wait for a thread specified by @a thread_id to exit and
>    * optionally returns its @a exit_status.  Does not wait on detached
>    * threads. 
>    * Can throw various exceptions on failure (TBD).
>    */
>   void wait (thread_t thread_id, void *exit_status = 0);

(Note that exit status part probably goes away if you use something like
Callable)


> 
>   /**
>    * Cancel a single thread.  Not supported on platforms
>    * that do not have advanced cancellation support.
>    * Can throw various exceptions on failure (TBD).
>    */
>   void cancel (thread_t, bool async_cancel = false);


Just right! (the "async_cancel" is basically the same as
we did for Futures in java.util.concurrent.)

> 
>   /// I've intentionally omitted all suspend()/resume() methods
>   /// since they are badly flawed, non-portable, and can't be used
>   /// properly.

We (for j.u.c) ended up liking "park/unpark" for this. It is defined
in a very portable way, and is VERY handy for building other things
with, but not very useful by itself, which is just perfect here.
See
http://gee.cs.oswego.edu/dl/jsr166/dist/docs/java/util/concurrent/locks/LockSupport.html

(We hid it away outside Thread class just to emphasize that it
is a building block.)


> 
> /**
>  * @class Thread_Group
>  *
>  * @brief Manages a group of threads.
>  *
>  * Allows operations on groups of threads atomically.
>  */
> 
> class Thread_Group
> {
>   /**
>    * Add @a thread_id to the group.
>    * Can throw various exceptions on failure (TBD).
>    */
>   void join (thread_t thread_id);

Is a Thread_group joined automatically when constructing thread?
Similarly for remove?


-Doug







More information about the cpp-threads mailing list