 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Boris Bralo Guest
|
Posted: Tue Oct 03, 2006 6:15 pm Post subject: Using variadic templates (N2080) with threads (N2090) |
|
|
Hi all,
I've just read newest WG21 mailings and I thing that threads proposal
can use variadic templates to have nicer API.
// create a thread executing f() with arguments args
template<class F, class... Args>
handle create( F f , const Args&& args...);
or even
template<class F, class... Args>
future< F::result_type > create( F f , const Args&& args...);
I agree that's just syntactic sugar, but I'm bored with void f(void) (or
void f(void*)) stuff in every single thread implementation I've encountered.
---
Boris
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ] |
|
| Back to top |
|
 |
loufoque Guest
|
Posted: Wed Oct 04, 2006 2:24 am Post subject: Re: Using variadic templates (N2080) with threads (N2090) |
|
|
Boris Bralo wrote :
| Quote: | I agree that's just syntactic sugar, but I'm bored with void f(void) (or
void f(void*)) stuff in every single thread implementation I've encountered.
|
You probably never saw boost.threads then.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ] |
|
| Back to top |
|
 |
Peter Dimov Guest
|
Posted: Wed Oct 04, 2006 3:45 am Post subject: Re: Using variadic templates (N2080) with threads (N2090) |
|
|
Boris Bralo wrote:
| Quote: | Hi all,
I've just read newest WG21 mailings and I thing that threads proposal
can use variadic templates to have nicer API.
// create a thread executing f() with arguments args
template<class F, class... Args
handle create( F f , const Args&& args...);
or even
template<class F, class... Args
future< F::result_type > create( F f , const Args&& args...);
I agree that's just syntactic sugar, but I'm bored with void f(void) (or
void f(void*)) stuff in every single thread implementation I've encountered.
|
You probably already know this, but still: the difference between the
N2090 interface and the above is one 'bind' call.
Eliminating the explicit 'bind' is a logical extension which I've
considered once or twice. On the one hand, forcing people to learn
about bind's existence is good, it allows them to solve the "how do I
pass arguments" problem when using other libraries taking a nullary
function object.
On the other hand, forcing people to learn bind when they just want to
spawn their threads (thankyouverymuch) is bad, and the ability to
simply say
handle th = thread::create( &X::f, &x );
has its appeal. We've learned from boost::thread that how to pass
arguments isn't obvious, and I've already offered one "convenience
overload" for other non-obviousness-reasons. So I'll probably include a
family of bind-invoking overloads in the next revision of N2090, if
there is one, unless I think of a killer argument against. (Variadic
templates and rvalue references would allow for a single function, but
it's still possible to achieve mostly the same effect in C++03.)
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ] |
|
| Back to top |
|
 |
Boris Bralo Guest
|
Posted: Wed Oct 04, 2006 4:07 pm Post subject: Re: Using variadic templates (N2080) with threads (N2090) |
|
|
hi loufoque,
| Quote: | Boris Bralo wrote :
I agree that's just syntactic sugar, but I'm bored with void f(void) (or
void f(void*)) stuff in every single thread implementation I've
encountered.
You probably never saw boost.threads then.
I've seen them all .(boost, ACE, qt, java, c#) |
Boost.threads is basically void f(void), except that functor is used.
Boris
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ] |
|
| Back to top |
|
 |
Boris Bralo Guest
|
Posted: Wed Oct 04, 2006 8:08 pm Post subject: Re: Using variadic templates (N2080) with threads (N2090) |
|
|
| Quote: |
I've just read newest WG21 mailings and I thing that threads proposal
can use variadic templates to have nicer API.
// create a thread executing f() with arguments args
template<class F, class... Args
handle create( F f , const Args&& args...);
You probably already know this, but still: the difference between the
N2090 interface and the above is one 'bind' call.
|
Yes, I know. As I said, it's merely syntactic sugar, but that's not
unimportant. Programming is, in part, literature.
| Quote: |
So I'll probably include a
family of bind-invoking overloads in the next revision of N2090, if
there is one, unless I think of a killer argument against. (Variadic
templates and rvalue references would allow for a single function, but
it's still possible to achieve mostly the same effect in C++03.)
Great. |
BTW I like your proposal. Looks more natural than boost.threads.
Boris
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ] |
|
| Back to top |
|
 |
kanze Guest
|
Posted: Thu Oct 05, 2006 3:44 pm Post subject: Re: Using variadic templates (N2080) with threads (N2090) |
|
|
Boris Bralo wrote:
| Quote: | Boris Bralo wrote :
I agree that's just syntactic sugar, but I'm bored with
void f(void) (or void f(void*)) stuff in every single
thread implementation I've encountered.
You probably never saw boost.threads then.
I've seen them all .(boost, ACE, qt, java, c#)
Boost.threads is basically void f(void), except that functor
is used.
|
And functors can have unlimited state, so there's no problem
what so ever with correctly typed input parameters. The functor
is copied, so you need an additional level of indirection for
output parameters and return values. But they remain fully
types.
--
James Kanze GABI Software
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ] |
|
| Back to top |
|
 |
Peter Dimov Guest
|
Posted: Tue Oct 10, 2006 11:36 pm Post subject: Re: Using variadic templates (N2080) with threads (N2090) |
|
|
Boris Bralo wrote:
| Quote: | So I'll probably include a
family of bind-invoking overloads in the next revision of N2090, if
there is one, unless I think of a killer argument against.
Great.
|
One problem with the idea is that the implementations were supposed to
be free to add additional arguments to the basic create( f ) in order
to support platform-specific creation parameters. (I neglected to
document that in N2090, though.)
An implementation layered on pthreads could potentially take a
pthread_attr_t in addition to f. With the argument overloads there
would be an ambiguity. This can probably be solved by putting the extra
platform-specific arguments in front of f.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ] |
|
| Back to top |
|
 |
Alexander Terekhov Guest
|
Posted: Thu Oct 12, 2006 8:40 pm Post subject: Re: Using variadic templates (N2080) with threads (N2090) |
|
|
Peter Dimov wrote:
| Quote: |
Boris Bralo wrote:
So I'll probably include a
family of bind-invoking overloads in the next revision of N2090, if
there is one, unless I think of a killer argument against.
Great.
One problem with the idea is that the implementations were supposed to
be free to add additional arguments to the basic create( f ) in order
to support platform-specific creation parameters. (I neglected to
document that in N2090, though.)
|
std::new_thread(f);
same as
std::thread_attr().new_thread(f);
Fancy stuff:
attr
.set_blah_blah()
.new_thread(f);
regards,
alexander.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ] |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|