giovedì 23 febbraio 2012 15:16
this is more a feature request or an idea for improvement, but I don't know where to submit this.
I was playing around with the concurrency runtime today, in particullar with concurrent_queue to implement a simple producer/consumer pattern to process a file. I use one thread to read chunks from a file and push them into a concurrent_queue object, which is accessed by the consumer thread to do some computation. It all works fine, but I think concurrent_queue would benefit from using r-value references and move semantics (same applies to concurrent_vector, i guess). Concurrent_queue has push method defined as
void push( const _Ty& _Src );
and a try_pop method defined as
bool try_pop( _Ty& _Dest );
I think it would match the intended semantics if I could move my objects into and out of the queue using std::move and move semantics, e.g. by using the move-assignment operator in try_pop.
Tutte le risposte
venerdì 2 marzo 2012 18:34
That's a good question. We are making our best effort to take advantage of new C++11 features in our product, which includes supporting move semantics in most of our concurrent containers. Though I cannot say how much we will support move semantics, but I think move semantic for concurrent_queue::push has been in VS11 developer previews. Just go and check them out :) .
For the try_pop(), I don't really understand what do you want it to be. To me the current signature seems to be optimal, since it has to renturn a boolean to indicate whether it's success or not.
martedì 13 marzo 2012 08:21
Thanks for your answer. I will certainly check out the new version in VS11, I just only some spare time.
For try_pop(), I am not sure what I meant when I wrote the post. I think I wanted to make sure that try_pop() uses move assignment internally when setting the output parameter.
Just for the records, I wouldn't say that try_pop() has an optimal sinature, at least when we consider other programming languages. What I think would be optimal would be something like a Maybe return type similar to Haskell or Scala's Option type. I don't think is possible in a useable way in C++ without users of the try_pop function using template metaprogramming for the type matching, but if anybody has an idea feel welcome to convince me.