Topic: Using variadic templates (N2080) with threads (N2090)
Author: "Peter Dimov" <pdimov@gmail.com>
Date: Tue, 10 Oct 2006 17:36:55 CST Raw View
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.)
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 ]
Author: terekhov@web.de (Alexander Terekhov)
Date: Thu, 12 Oct 2006 15:40:31 GMT Raw View
Peter Dimov wrote:
>
> 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 ]
Author: "kanze" <kanze@gabi-soft.fr>
Date: Thu, 5 Oct 2006 09:44:45 CST Raw View
Boris Bralo wrote:
> > 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 ]
Author: Boris Bralo <boris.bralo@gmail.com>
Date: Tue, 3 Oct 2006 12:15:43 CST Raw View
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 ]
Author: loufoque@remove.gmail.com (loufoque)
Date: Tue, 3 Oct 2006 21:24:30 GMT Raw View
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.
---
[ 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 ]
Author: "Peter Dimov" <pdimov@gmail.com>
Date: Tue, 3 Oct 2006 21:45:39 CST Raw View
Boris Bralo wrote:
> 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 ]
Author: Boris Bralo <boris.bralo@gmail.com>
Date: Wed, 4 Oct 2006 10:07:45 CST Raw View
hi loufoque,
> 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 ]
Author: boris.bralo@gmail.com (Boris Bralo)
Date: Wed, 4 Oct 2006 15:08:08 GMT Raw View
>>
>> 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.
>
> 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 ]