Should threading be in the Standard?

Discussion in 'C++' started by Steven T. Hatton, Sep 4, 2004.

  1. I pinned this to my desktop a while back so I'd remember to look at it:

    I just started reading it and realized that there may be a reason to extend the
    language to support threading:

    Increasing use of threads lead developers to wish for a better way of dealing with
    thread-local data. The POSIX thread interface defines interfaces which allow storing
    void * objects separate for each thread. But the interface is cumbersome to use. A key
    for the object has to be allocated dynamically at run-time. If the key isn't used anymore
    it must be freed. While this is already a lot of work and error prone it becomes a real
    problem when combined with dynamically loaded code.
    To counter these problems it was decided to extend the programming languages to
    let the compiler take over the job. For C and C++ the new keyword thread can be
    used in variable definitions and declarations. This is not an official extension of the
    language but compiler writers are encouraged to implement them to support the new
    ABI. Variables defined and declared this way would automatically be allocated local to
    each thread:
    __thread int i;
    __thread struct state s;
    extern __thread char *p;
    The usefulness of this is not limited to user-programs. The run-time environment
    can also take advantage of it (e.g., the global variable errno must be thread-local)
    and compilers can perform optimizations which create non-automatic variables. Note
    that adding thread to the definition of an automatic variable makes no sense and is
    not allowed since automatic variables are always thread-local. Static function-scope
    variables on the other hands are candidates, though.

    "[M]y dislike for the preprocessor is well known. Cpp is essential in C programming, and still important in conventional C++ implementations, but it is a hack, and so are most of the techniques that rely on it. ...I think the time has come to be serious about macro-free C++ programming." - B. S.
    Steven T. Hatton, Sep 4, 2004
    1. Advertisements

  2. Steven T. Hatton wrote:
    > I just started reading it and realized that there may be a reason to extend the
    > language to support threading:
    > [...]
    > Opinions?

    There is a thread currently active in comp.lang.c++.moderated and
    in comp.std.c++ related to specifically threads and C++ Standard,
    perhaps you could read the opinions there.
    Victor Bazarov, Sep 7, 2004
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    Mark Space
    Dec 29, 2007
  2. James Kanze

    Re: Threading in new C++ standard

    James Kanze, Apr 16, 2008, in forum: C++
    James Kanze
    Apr 18, 2008
  3. Ke Jin
    red floyd
    May 23, 2008
  4. Steven Woody
    Steven Woody
    Jan 9, 2009
  5. Steven Woody
    Steven Woody
    Jan 9, 2009

Share This Page