Note that there are some explanatory texts on larger screens.

plurals
  1. POIn the Concurrency Runtime, can I use parallel_invoke or task_group with non-const function objects?
    primarykey
    data
    text
    <p>I'm using the Concurrency Runtime with Visual C++ 2010, and am interested in the capabilities of <a href="http://msdn.microsoft.com/en-us/library/dd470426.aspx" rel="nofollow">parallel_invoke</a> and <a href="http://msdn.microsoft.com/en-us/library/dd492427.aspx" rel="nofollow">task_group</a> (parts of the PPL or <a href="http://msdn.microsoft.com/en-us/library/dd492418.aspx" rel="nofollow">Parallel Patterns Library</a>). I'd like to be able to start two parallel actions via function objects (rather than lambda functions or function pointers), but I can't get the code to compile, because of an error:</p> <pre><code>error C3848: expression having type 'const C' would lose some const-volatile qualifiers in order to call 'void C::operator ()(void)' </code></pre> <p>But if I make the C::operator()() const, then I lose a lot of the benefits of a function object, namely, that its state is mutable and maintained internally between calls. Am I missing something here? Is there a way that I could invoke non-const function objects in parallel?</p> <p>BTW, I realize that I could use the <a href="http://msdn.microsoft.com/en-us/library/dd492627.aspx" rel="nofollow">Asynchronous Agents Library</a>, and derive the classes from the Concurrency::agent class, but please consider that beyond the scope of this question (in part due to the lack of exception handling and cancellation options).</p> <p>I'm just interested in what I can do with the PPL, and while there are examples with lambda functions and function pointers, I couldn't find or create any examples with function objects that do more than a parallel "Hello World". I'm looking for something that really takes advantage of function objects, and, if possible, also concurrent containers.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload