- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个解决那些二维迷宫的程序,它对我来说工作得很好,但是我用 gprof
(和@jrfonseca 的花式 gprof2dot )对它进行了分析,在我看来它是在一些操作上遇到困难,并决定进行一些并行化尝试。
基本上,在一个消耗 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$
...在这种情况下?
一些find_path.cpp:
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 );
void move(12)
中的内容:
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 }
它告诉我明确标记为已删除 ~__nat
,我什至不记得做过这样的事情。
我有点习惯 pthreads、Python 线程、Java 并行模型……不太了解不确定的选择、一般的异步、promises……我应该放弃努力离开 std::future
有什么用?
最佳答案
该错误消息与一个新的 C++ 功能有关,即“删除”默认运算符以使其不可访问(以前,通常的技术是将它们设为私有(private))。
在您的情况下,它表示线程构造函数的参数存在问题。您的代码非常复杂,但您可能遇到过这个问题:C++ std::thread "Attempt to use a deleted function"
我肯定会建议继续使用 std:future。作为介绍,强烈推荐 Herb Sutter 关于新的 C++ 并发特性的以下演讲:https://channel9.msdn.com/Shows/Going+Deep/C-and-Beyond-2012-Herb-Sutter-Concurrency-and-Parallelism
关于c++ - 这个奇怪的 clang 编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33110365/
我已经使用 vue-cli 两个星期了,直到今天一切正常。我在本地建立这个项目。 https://drive.google.com/open?id=0BwGw1zyyKjW7S3RYWXRaX24tQ
您好,我正在尝试使用 python 库 pytesseract 从图像中提取文本。请找到代码: from PIL import Image from pytesseract import image_
我的错误 /usr/bin/ld: errno: TLS definition in /lib/libc.so.6 section .tbss mismatches non-TLS reference
我已经训练了一个模型,我正在尝试使用 predict函数但它返回以下错误。 Error in contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]])
根据Microsoft DataConnectors的信息我想通过 this ODBC driver 创建一个从 PowerBi 到 PostgreSQL 的连接器使用直接查询。我重用了 Micros
我已经为 SoundManagement 创建了一个包,其中有一个扩展 MediaPlayer 的类。我希望全局控制这个变量。这是我的代码: package soundmanagement; impo
我在Heroku上部署了一个应用程序。我正在使用免费服务。 我经常收到以下错误消息。 PG::Error: ERROR: out of memory 如果刷新浏览器,就可以了。但是随后,它又随机发生
我正在运行 LAMP 服务器,这个 .htaccess 给我一个 500 错误。其作用是过滤关键字并重定向到相应的域名。 Options +FollowSymLinks RewriteEngine
我有两个驱动器 A 和 B。使用 python 脚本,我在“A”驱动器中创建一些文件,并运行 powerscript,该脚本以 1 秒的间隔将驱动器 A 中的所有文件复制到驱动器 B。 我在 powe
下面的函数一直返回这个错误信息。我认为可能是 double_precision 字段类型导致了这种情况,我尝试使用 CAST,但要么不是这样,要么我没有做对...帮助? 这是错误: ERROR: i
这个问题已经有答案了: Syntax error due to using a reserved word as a table or column name in MySQL (1 个回答) 已关闭
我的数据库有这个小问题。 我创建了一个表“articoli”,其中包含商品的品牌、型号和价格。 每篇文章都由一个 id (ID_ARTICOLO)` 定义,它是一个自动递增字段。 好吧,现在当我尝试插
我是新来的。我目前正在 DeVry 在线学习中级 C++ 编程。我们正在使用 C++ Primer Plus 这本书,到目前为止我一直做得很好。我的老师最近向我们扔了一个曲线球。我目前的任务是这样的:
这个问题在这里已经有了答案: What is an undefined reference/unresolved external symbol error and how do I fix it?
我的网站中有一段代码有问题;此错误仅发生在 Internet Explorer 7 中。 我没有在这里发布我所有的 HTML/CSS 标记,而是发布了网站的一个版本 here . 如您所见,我在列中有
如果尝试在 USB 设备上构建 node.js 应用程序时在我的树莓派上使用 npm 时遇到一些问题。 package.json 看起来像这样: { "name" : "node-todo",
在 Python 中,您有 None单例,在某些情况下表现得很奇怪: >>> a = None >>> type(a) >>> isinstance(a,None) Traceback (most
这是我的 build.gradle (Module:app) 文件: apply plugin: 'com.android.application' android { compileSdkV
我是 android 的新手,我的项目刚才编译和运行正常,但在我尝试实现抽屉导航后,它给了我这个错误 FAILURE: Build failed with an exception. What wen
谁能解释一下?我想我正在做一些非常愚蠢的事情,并且急切地等待着启蒙。 我得到这个输出: phpversion() == 7.2.25-1+0~20191128.32+debian8~1.gbp108
我是一名优秀的程序员,十分优秀!