Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 这是一个奇怪的编译错误_C++_Multithreading_C++11_Clang_Future - Fatal编程技术网

C++ 这是一个奇怪的编译错误

C++ 这是一个奇怪的编译错误,c++,multithreading,c++11,clang,future,C++,Multithreading,C++11,Clang,Future,我有一个解决二维迷宫的程序,它对我来说运行得很好,但是我用gprof(和@jrfonseca的想象)对它进行了分析,在我看来,它在一些操作上花了很长时间,并决定做一些并行化尝试 基本上,在一个消耗了50%(CPU)时间的函数中,我有两个并行选择(单个队列的多个用户和相同函数的并行调用,具有相似的不相等的参数),但首先希望独立地检查两个初始假设,哪一个更好,我不总是做C++代码,通过在互联网上搜索如何获取std::thread返回值,我阅读了一个关于std::future的建议的很好的答案,然后我

我有一个解决二维迷宫的程序,它对我来说运行得很好,但是我用
gprof
(和@jrfonseca的想象)对它进行了分析,在我看来,它在一些操作上花了很长时间,并决定做一些并行化尝试

基本上,在一个消耗了50%(CPU)时间的函数中,我有两个并行选择(单个队列的多个用户和相同函数的并行调用,具有相似的不相等的参数),但首先希望独立地检查两个初始假设,哪一个更好,我不总是做C++代码,通过在互联网上搜索如何获取

std::thread
返回值,我阅读了一个关于
std::future
的建议的很好的答案,然后我将其复制到我的代码中,请您知道这意味着什么

bash-4.3$ sh build.sh
In file included from find_path.cpp:6:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/Xco
deDefault.xctoolchain/usr/bin/../include/c++/v1/future:371:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/
usr/bin/../include/c++/v1/thread:337:5: error:
      attempt to use a deleted function
    __invoke(_VSTD::move(_VSTD::get<0>(__t)), _VSTD::move(_VSTD::get<_In...
    ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/
usr/bin/../include/c++/v1/thread:347:5:
      in instantiation of function template specialization
      'std::__1::__thread_execute<void
      (*)(std::__1::priority_queue<std::__1::vector<std::__1::pair<int, int>,
      std::__1::allocator<std::__1::pair<int, int> > >,
      std::__1::vector<std::__1::vector<std::__1::pair<int, int>,
      std::__1::allocator<std::__1::pair<int, int> > >,
      std::__1::allocator<std::__1::vector<std::__1::pair<int, int>,
      std::__1::allocator<std::__1::pair<int, int> > > > >, NearerTarget> &,
      std::__1::vector<std::__1::pair<int, int>,
      std::__1::allocator<std::__1::pair<int, int> > > &, std::__1::pair<int,
      int> &, int, int, int, int, unsigned char *,
      std::__1::vector<std::__1::pair<int, int>,
      std::__1::allocator<std::__1::pair<int, int> > > &, int, int,
      std::__1::promise<bool> &&),
      std::__1::reference_wrapper<std::__1::priority_queue<std::__1::vector<std
::__1::pair<int,
      int>, std::__1::allocator<std::__1::pair<int, int> > >,
      std::__1::vector<std::__1::vector<std::__1::pair<int, int>,
      std::__1::allocator<std::__1::pair<int, int> > >,
      std::__1::allocator<std::__1::vector<std::__1::pair<int, int>,
      std::__1::allocator<std::__1::pair<int, int> > > > >, NearerTarget> >,
      std::__1::reference_wrapper<std::__1::vector<std::__1::pair<int, int>,
      std::__1::allocator<std::__1::pair<int, int> > > >,
      std::__1::reference_wrapper<std::__1::pair<int, int> >, int, int, int,
      int, const unsigned char *,
      std::__1::reference_wrapper<std::__1::vector<std::__1::pair<int, int>,
      std::__1::allocator<std::__1::pair<int, int> > > >, int, int,
      std::__1::promise<bool> , 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12>'
      requested here
    __thread_execute(*__p, _Index());
    ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/
usr/bin/../include/c++/v1/thread:359:42: note:
      in instantiation of function template specialization
      'std::__1::__thread_proxy<std::__1::tuple<void
      (*)(std::__1::priority_queue<std::__1::vector<std::__1::pair<int, int>,
      std::__1::allocator<std::__1::pair<int, int> > >,
      std::__1::vector<std::__1::vector<std::__1::pair<int, int>,
      std::__1::allocator<std::__1::pair<int, int> > >,
      std::__1::allocator<std::__1::vector<std::__1::pair<int, int>,
      std::__1::allocator<std::__1::pair<int, int> > > > >, NearerTarget> &,
      std::__1::vector<std::__1::pair<int, int>,
      std::__1::allocator<std::__1::pair<int, int> > > &, std::__1::pair<int,
      int> &, int, int, int, int, unsigned char *,
      std::__1::vector<std::__1::pair<int, int>,
      std::__1::allocator<std::__1::pair<int, int> > > &, int, int,
      std::__1::promise<bool> &&),
      std::__1::reference_wrapper<std::__1::priority_queue<std::__1::vector<std
::__1::pair<int,
      int>, std::__1::allocator<std::__1::pair<int, int> > >,
      std::__1::vector<std::__1::vector<std::__1::pair<int, int>,
      std::__1::allocator<std::__1::pair<int, int> > >,
      std::__1::allocator<std::__1::vector<std::__1::pair<int, int>,
      std::__1::allocator<std::__1::pair<int, int> > > > >, NearerTarget> >,
      std::__1::reference_wrapper<std::__1::vector<std::__1::pair<int, int>,
      std::__1::allocator<std::__1::pair<int, int> > > >,
      std::__1::reference_wrapper<std::__1::pair<int, int> >, int, int, int,
      int, const unsigned char *,
      std::__1::reference_wrapper<std::__1::vector<std::__1::pair<int, int>,
      std::__1::allocator<std::__1::pair<int, int> > > >, int, int,
      std::__1::promise<bool> > >' requested here
    int __ec = pthread_create(&__t_, 0, &__thread_proxy<_Gp>, __p.get());
                                         ^
find_path.cpp:258:25: note: in instantiation of function template specializatio
n
      'std::__1::thread::thread<void
      (*)(std::__1::priority_queue<std::__1::vector<std::__1::pair<int, int>,
      std::__1::allocator<std::__1::pair<int, int> > >,
      std::__1::vector<std::__1::vector<std::__1::pair<int, int>,
      std::__1::allocator<std::__1::pair<int, int> > >,
      std::__1::allocator<std::__1::vector<std::__1::pair<int, int>,
      std::__1::allocator<std::__1::pair<int, int> > > > >, NearerTarget> &,
      std::__1::vector<std::__1::pair<int, int>,
      std::__1::allocator<std::__1::pair<int, int> > > &, std::__1::pair<int,
      int> &, int, int, int, int, unsigned char *,
      std::__1::vector<std::__1::pair<int, int>,
      std::__1::allocator<std::__1::pair<int, int> > > &, int, int,
      std::__1::promise<bool> &&),
      std::__1::reference_wrapper<std::__1::priority_queue<std::__1::vector<std
::__1::pair<int,
      int>, std::__1::allocator<std::__1::pair<int, int> > >,
      std::__1::vector<std::__1::vector<std::__1::pair<int, int>,
      std::__1::allocator<std::__1::pair<int, int> > >,
      std::__1::allocator<std::__1::vector<std::__1::pair<int, int>,
      std::__1::allocator<std::__1::pair<int, int> > > > >, NearerTarget> >,
      std::__1::reference_wrapper<std::__1::vector<std::__1::pair<int, int>,
      std::__1::allocator<std::__1::pair<int, int> > > >,
      std::__1::reference_wrapper<std::__1::pair<int, int> >, int &, int &,
      const int &, const int &, const unsigned char *&,
      std::__1::reference_wrapper<std::__1::vector<std::__1::pair<int, int>,
      std::__1::allocator<std::__1::pair<int, int> > > >, const int &, int,
      std::__1::promise<bool> , void>' requested here
            std::thread n(&move, std::ref(active_paths),
                        ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/
usr/bin/../include/c++/v1/type_traits:1043:5: note:
      '~__nat' has been explicitly marked deleted here
    ~__nat() = delete;
    ^
1 error generated.
bash-4.3$
它告诉我,我明确地标记了deleted
~\uu nat
,我甚至不记得做过这样的梦


我有些习惯于pthreads、Python线程、Java并行模型。。。不太精通不确定的选择,通常异步,承诺。。。我应该付出努力,离开<代码> STD::未来< /Cord>使用?< /p> < P>错误消息涉及一个新的C++特性,“删除”默认操作符使它们不可访问(以前,通常的技术是使它们私有)。p> 在您的例子中,它表明线程构造函数的参数存在问题。您的代码相当复杂,但可能遇到以下问题:


我当然会建议继续使用std:future。作为介绍,,下面是萨特对新C++并发特性的讨论:

请显示FunthPosith.CPP:258,您的函数“代码>移动< /COD>接受<代码> PrimyIyQueLe>代码,当您试图在第258行创建一个线程时,您不提供一个。<代码>
std::priority\u queue>,std::vector>,NearerTarget>&
作为其第一个参数,然后向其传递
std::priority\u queue,std::vector>,NearerTarget>)
什么是“操作员”?那里没有默认运算符。有
结构NearerTarget{bool operator()(const std::vector&lhs,const std::vector&rhs)const{/*bleh bleh boolean something*/return(something);}但与编译问题无关。
 1  //   For 'assert(expression)'.
 2  #include <cassert>
 3  //   For 'std::abs' (absolute value function, integers version)'.
 4  #include <cstdlib>
 5  //   For 'std::promise' and 'std::future'.
 6  #include <future>  // <--
 7  //   For 'std::mutex'.
 8  #include <mutex>
 9  //   For 'std::priority_queue'.
10  #include <queue>
11  //   For 'std::move'.
12  #include <utility>
13  //   For 'std::vector'.
14  #include <vector>
15  //   For 'std::thread'.
16  #include <thread>
17  //   For 'std::get', 'std::make_tuple' and 'std::tuple'.
18  #include <tuple>
242             //   Do not add new paths unless deemed necessary.
243             bool add_north_move, add_west_move, add_south_move, add_east_move;
244             add_north_move = add_west_move = add_south_move = add_east_move =
245                 0;
246 
247             //   Another helper.
248             std::vector < std::pair < int, int > > active_paths_top =
249                 active_paths.top();
250             std::pair < int, int > active_paths_top_back =
251                 active_paths_top.back();
252 
253             //   Directions clockwise (0: 'N', 1: 'E', 2: 'S', 3: 'W').
254             int direction = 0;
255 
256             std::promise < bool > n_p;
257             auto n_f = n_p.get_future();
258             std::thread n(&move, std::ref(active_paths),  // <--
259                           std::ref(active_paths_top),
260                           std::ref(active_paths_top_back), new_move_back_x, new_move_back_y,
261               nMapWidth, nMapHeight, pMap, std::ref(north_move), nOutBufferSize, direction++, std::move(n_p)
262             );
263             std::promise < bool > e_p;
264             auto e_f = e_p.get_future();
265             std::thread e(&move, std::ref(active_paths),
266                           std::ref(active_paths_top),
267                           std::ref(active_paths_top_back), new_move_back_x, new_move_back_y,
268               nMapWidth, nMapHeight, pMap, std::ref(east_move), nOutBufferSize, direction++, std::move(e_p)
269             );
108 void move(std::priority_queue <
109         std::vector < std::pair < int, int > >,
110         std::vector < std::vector < std::pair < int, int > > >,
111         NearerTarget
112     > & active_paths,
113     std::vector < std::pair < int, int > > & active_paths_top,
114     std::pair < int, int > & active_paths_top_back, int new_move_back_x, int new_move_back_y,
115     int map_width, int map_height, unsigned char * map, std::vector < std::pair < int, int > > & move,
116     int out_buffer_size, int direction,
117     std::promise < bool > && add_move) {
118     assert(-1 < direction && 4 > direction);
119     std::pair < int, int > new_coord;
120     switch (direction) {
121     case 0:
122             //   Add move 'N'.
123             new_coord = std::make_pair(
124                     active_paths_top_back.first,
125                     active_paths_top_back.second + 1);
126             break;
127     case 1:
128             //   Add move 'E'.
129             new_coord = std::make_pair(
130                     active_paths_top_back.first + 1,
131                     active_paths_top_back.second);
132             break;
133     case 2:
134             //   Add move 'S'.
135             new_coord = std::make_pair(
136                     active_paths_top_back.first,
137                     active_paths_top_back.second - 1);
138             break;
139     case 3:
140             //   Add move 'W'.
141             new_coord = std::make_pair(
142                     active_paths_top_back.first - 1,
143                     active_paths_top_back.second);
144             break;
145     }
146 
147             //   Push it to the queue of paths only if the movement
148             // makes sense.
149             new_move_back_x = new_coord.first;
150             new_move_back_y = new_coord.second;
151             if (new_move_back_x > -1 && new_move_back_x < map_width &&
152                     new_move_back_y > -1 && new_move_back_y < map_height)
153             {
154                 //   Move is inside bounds.
155 
156                 //   Check collision detection.
157                 if (map[new_move_back_y * map_width + new_move_back_x])
158                 {
159                     //   Check not visited.
160                     if (! visited(
161                                 new_move_back_x,
162                                 new_move_back_y,
163                                 active_paths.top()))
164                     {
165                         move = active_paths_top;
166                         move.reserve(out_buffer_size);
167                         move.push_back(new_coord);
168                         add_move.set_value(true);
169                     }
170                 }
171             }
172 }