https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80038

--- Comment #5 from Florent Hivert <florent.hivert at lri dot fr> ---
(In reply to Richard Biener from comment #3)
> Don't know Cilk+ but yes, try
> 
>    for (int i=0; i<8; i++) {
>       std::vector<int> vnew(v);
>       vnew.push_back(i);
>       cilk_spawn walk(vnew, size);
>       cilk_sync;
>     }
> 
> with appropriate syntax.

Ok ! Putting the cilk_sync here works but completely destroy the purpose of
using Cilk (no parallelism). I had the feeling that passing vnew as a value to
the function makes a copy so there is no possibility for the caller to destroy
vnew before it gets copied by the function call.  

However using manual allocation seems to fix the problem

#include <vector>
#include <cilk/cilk.h>

void walk(std::vector<int> *v, unsigned size) {
  if (v->size() < size)
    for (int i=0; i<8; i++) {
      auto *vnew = new std::vector<int>(*v);
      vnew->push_back(i);
      cilk_spawn walk(vnew, size);
    }
  cilk_sync;
  delete v;
}

int main(int argc, char **argv) {
  auto *v = new std::vector<int>{};
  walk(v, 5);
}

Reply via email to