Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.std.c++ > #556

Re: Defect Report: packaged_task is too strongly typed

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date Sun, 04 Nov 2012 21:20:02 -0600
Return-Path <cppmods@mcgurn.dreamhost.com>
Sender std-cpp-request@vandevoorde.com
Approved james.dennett@gmail.com
Message-ID <k76k5e$6d1$1@dont-email.me> (permalink)
Newsgroups comp.std.c++
From Daniel Krügler <daniel.kruegler@googlemail.com>
Subject Re: Defect Report: packaged_task is too strongly typed
Organization A noiseless patient Spider
References <5095A1F0.9000407@amacapital.net>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
X-Original-Date Sun, 04 Nov 2012 21:45:33 +0100
X-Submission-Address std-cpp-submit@vandevoorde.com
To undisclosed-recipients:;
X-Spam-Status No, score=2.0 required=5.0 tests=FREEMAIL_FROM,HEADER_SPAM, RP_MATCHES_RCVD,SARE_HEAD_HDR_APPROV,UNPARSEABLE_RELAY autolearn=disabled version=3.3.1
X-Spam-Level *
X-Spam-Checker-Version SpamAssassin 3.3.1 (2010-03-16) on harlem.dreamhost.com
Date Sun, 4 Nov 2012 21:16:35 CST
Lines 66
X-Usenet-Provider http://www.giganews.com
X-Trace sv3-xsEtpIICl17GUJ79lBEMe52DWg55SZYjmAC4XjWdAN7R20XJBrV+AabmW5No/jpRpdlzXZoAQk9e7ON!nV79tdwR7oQdB/YS9rxta+CPDwp6HW7PXRHKaTf4Sip/H0mR6GQ=
X-Complaints-To abuse@giganews.com
X-DMCA-Notifications http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info Otherwise we will be unable to process your complaint properly
X-Postfilter 1.3.40
X-Original-Bytes 3771
Xref csiph.com comp.std.c++:556

Show key headers only | View raw



Am 04.11.2012 20:42, schrieb Andy Lutomirski:
>
> packaged_task is almost perfect for use in custom thread pools, like this:
>
> packaged_task<int> task([] { /* something */ });

This example cannot work, because packaged_task can only be
instantiated with a function type, but 'int' isn't such a beast.

> future<int> result;
> threadpool.submit(task);
>
> // later on
> int x = result.get();
>
> This doesn't work well, though: the threadpool.submit() function would
> like to accept packaged_task<T> for any T -- the only packaged_task
> functionality that depends on the return type (as opposed to the
> parameter type) is get_future, and get_future can only be called once.
>
> This means that the submit function would need to be a template and use
> some unnecessarily complicated trick to deal with different
> packaged_task types.

I'm unconvinced that what you are describing here really is a defect.

It sounds as if you say that for similar reasons std::function
shouldn't be a template that depends on a function type. The current
design of packaged_task makes perfect sense, because a packaged_task
represents a type that wraps any function-like object (very similar to
std::function) and it also allows to call invoke this callable via a
corresponding set of functions:

void operator()(ArgTypes... );
void make_ready_at_thread_exit(ArgTypes...);

Obviously these depend on the remaining parts of the signature. So
this seems to invalidate your claims above.

> Any number of fixes are possible.  For example, packaged_task<void,
> ArgTypes...>

Do you mean packaged_task<void(ArgTypes...)> ?

> could have a member
> template<typename F>
> static pair<future<R>, packaged_task<void, ArgTypes...>>
> create_void(F&& f);

I don't see how this would work, if either the return type or the
argument types are missing.

HTH & Greetings from Bremen,

Daniel Krügler



--
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]

Back to comp.std.c++ | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Defect Report: packaged_task is too strongly typed Andy Lutomirski <luto@amacapital.net> - 2012-11-04 13:42 -0600
  Re: Defect Report: packaged_task is too strongly typed Daniel Krügler <daniel.kruegler@googlemail.com> - 2012-11-04 21:16 -0600
    Re: Defect Report: packaged_task is too strongly typed Andy Lutomirski <luto@amacapital.net> - 2012-11-13 12:39 -0800
      Re: Defect Report: packaged_task is too strongly typed Daniel Krügler <daniel.kruegler@googlemail.com> - 2012-11-21 11:23 -0800
      Re: Defect Report: packaged_task is too strongly typed Daniel Krügler <daniel.kruegler@googlemail.com> - 2012-11-21 11:27 -0800

csiph-web