- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
所以当我用多个线程运行时,我总是遇到段错误:
class InvertedIndex {
private:
unordered_map<string, Details> index;
mutex indexInsert;
public:
void addTerms(pair<string, list<string>> parsedReport) {
unordered_map<string, Details>::iterator indexIterator;
for (auto term = parsedReport.second.begin(); term != parsedReport.second.end(); ++term) {
indexInsert.lock();
indexIterator = index.find(*term);
if (indexIterator == index.end()) {
Details details;
details.addOccurrence(parsedReport.first);
index.insert(pair <string, Details> (*term, details));
} else
indexIterator->second.addOccurrence(parsedReport.first);
indexInsert.unlock();
}
}
}
当我用 GDB 调试程序时,它告诉我问题出在 index.find(*term),与散列有关。当我用单个线程运行它时它运行良好,我觉得这很奇怪,因为我在它周围加了锁。
编辑:这是请求的堆栈跟踪:
Using host libthread_db library "/lib64/libthread_db.so.1".
[New Thread 0x7ffff75de700 (LWP 3842)]
[New Thread 0x7ffff6ddd700 (LWP 3843)]
[New Thread 0x7ffff65dc700 (LWP 3844)]
[New Thread 0x7ffff5ddb700 (LWP 3845)]
[New Thread 0x7ffff55da700 (LWP 3846)]
[New Thread 0x7ffff4dd9700 (LWP 3847)]
[New Thread 0x7ffff45d8700 (LWP 3848)]
[New Thread 0x7ffff3dd7700 (LWP 3849)]
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff65dc700 (LWP 3844)]
0x000000000041c8bf in std::__detail::_Hash_code_base<std::string, std::pair<std::string const, Details>, std::_Select1st<std::pair<std::string const, Details> >, std::hash<std::string>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true>::_M_bucket_index (this=0x7fffffffde10, __p=0xc0, __n=467) at /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/hashtable_policy.h:793
793 { return _M_h2()(__p->_M_hash_code, __n); }
(gdb) bt
#0 0x000000000041c8bf in std::__detail::_Hash_code_base<std::string, std::pair<std::string const, Details>, std::_Select1st<std::pair<std::string const, Details> >, std::hash<std::string>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true>::_M_bucket_index (this=0x7fffffffde10, __p=0xc0, __n=467)
at /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/hashtable_policy.h:793
#1 0x0000000000419591 in std::_Hashtable<std::string, std::pair<std::string const, Details>, std::allocator<std::pair<std::string const, Details> >, std::_Select1st<std::pair<std::string const, Details> >, std::equal_to<std::string>, std::hash<std::string>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, true, false, true>::_M_bucket_index (
this=0x7fffffffde10, __n=0xc0) at /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/hashtable.h:461
#2 0x000000000041561c in std::_Hashtable<std::string, std::pair<std::string const, Details>, std::allocator<std::pair<std::string const, Details> >, std::_Select1st<std::pair<std::string const, Details> >, std::equal_to<std::string>, std::hash<std::string>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, true, false, true>::_M_find_before_node (
this=0x7fffffffde10, __n=57, __k="bypass", __code=1325113244381254371) at /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/hashtable.h:1081
#3 0x0000000000410672 in std::_Hashtable<std::string, std::pair<std::string const, Details>, std::allocator<std::pair<std::string const, Details> >, std::_Select1st<std::pair<std::string const, Details> >, std::equal_to<std::string>, std::hash<std::string>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, true, false, true>::_M_find_node (
this=0x7fffffffde10, __bkt=57, __key="bypass", __c=1325113244381254371) at /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/hashtable.h:478
#4 0x000000000040c9e6 in std::_Hashtable<std::string, std::pair<std::string const, Details>, std::allocator<std::pair<std::string const, Details> >, std::_Select1st<std::pair<std::string const, Details> >, std::equal_to<std::string>, std::hash<std::string>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, true, false, true>::find (this=0x7fffffffde10, __k=
"bypass") at /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/hashtable.h:939
#5 0x0000000000408e50 in InvertedIndex::addTerms (this=0x7fffffffdd00, parsedReport=...) at InvertedIndex.hpp:83
#6 0x00000000004091f2 in InvertedIndex::addReport (this=0x7fffffffdd00, fileName="/home/brodie/workspace/inverted_index/resources/test_reports/report6.xml") at InvertedIndex.hpp:104
#7 0x0000000000409e26 in InvertedIndex::loadIndex()::{lambda()#1}::operator()() const (__closure=0x6448e0) at InvertedIndex.hpp:169
#8 0x0000000000425128 in std::_Function_handler<void (), InvertedIndex::loadIndex()::{lambda()#1}>::_M_invoke(std::_Any_data const&) (__functor=...)
at /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/functional:1926
#9 0x0000000000426ba4 in std::function<void ()>::operator()() const (this=0x6448b0) at /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/functional:2311
#10 0x0000000000426df1 in std::__invoke<std::function<void ()>>(std::function<void ()>&) (__f=...) at /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/functional:235
#11 0x0000000000426dc6 in std::reference_wrapper<std::function<void ()> >::operator()<>() const (this=0x7ffff65dbcc0) at /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/functional:468
#12 0x0000000000426cc2 in std::_Bind_simple<std::reference_wrapper<std::function<void ()> > ()>::_M_invoke<>(std::_Index_tuple<>) (this=0x7ffff65dbcc0)
at /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/functional:1598
#13 0x0000000000426a3b in std::_Bind_simple<std::reference_wrapper<std::function<void ()> > ()>::operator()() (this=0x7ffff65dbcc0)
at /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/functional:1586
#14 0x0000000000426717 in std::_Function_handler<void (), std::reference_wrapper<std::_Bind_simple<std::reference_wrapper<std::function<void ()> > ()> > >::_M_invoke(std::_Any_data const&) (__functor=...)
at /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/functional:1956
#15 0x0000000000426ba4 in std::function<void ()>::operator()() const (this=0x7fffd40008c8) at /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/functional:2311
#16 0x000000000042681e in std::__future_base::_Task_setter<std::unique_ptr<std::__future_base::_Result<void>, std::__future_base::_Result_base::_Deleter>, void>::operator() (this=0x7fffd40008c0)
at /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/future:1236
#17 0x0000000000426587 in std::_Function_handler<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> (), std::__future_base::_Task_setter<std::unique_ptr<std::__future_base::_Result<void>, std::__future_base::_Result_base::_Deleter>, void> >::_M_invoke(std::_Any_data const&) (__functor=...) at /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/functional:1912
#18 0x000000000040bde5 in std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>::operator()() const (this=0x7ffff65dbce0)
#19 0x0000000000408568 in std::__future_base::_State_base::_M_do_set(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>&, bool&) (this=0x644838,
__f=..., __set=@0x7ffff65dbc1f: false) at /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/future:473
#20 0x000000000041b403 in std::_Mem_fn<void (std::__future_base::_State_base::*)(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>&, bool&)>::operator()(std::__future_base::_State_base*, std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>&, bool&) const (this=0x7ffff65dbba8, __object=0x644838,
__args#0=..., __args#1=@0x7ffff65dbc1f: false) at /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/functional:554
#21 0x00000000004184fb in std::_Bind_simple<std::_Mem_fn<void (std::__future_base::_State_base::*)(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>&, bool&)> (std::__future_base::_State_base*, std::reference_wrapper<std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()> >, std::reference_wrapper<bool>)>::_M_invoke<0ul, 1ul, 2ul>(std::_Index_tuple<0ul, 1ul, 2ul>) (this=0x7ffff65dbb90) at /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/functional:1598
#22 0x000000000041429f in std::_Bind_simple<std::_Mem_fn<void (std::__future_base::_State_base::*)(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>&, bool&)> (std::__future_base::_State_base*, std::reference_wrapper<std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()> >, std::reference_wrapper<bool>)>::operator()() (this=0x7ffff65dbb90) at /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/functional:1586
#23 0x000000000040fa7f in std::__once_call_impl<std::_Bind_simple<std::_Mem_fn<void (std::__future_base::_State_base::*)(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>&, bool&)> (std::__future_base::_State_base*, std::reference_wrapper<std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()> >, std::reference_wrapper<bool>)> >() () at /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/mutex:787
#24 0x00000036e920cac0 in pthread_once () at ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S:103
#25 0x0000000000404266 in __gthread_once (__once=0x6448a4, __func=0x403eb0 <__once_proxy@plt>) at /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/x86_64-redhat-linux/bits/gthr-default.h:718
#26 0x000000000040bc8d in std::call_once<void (std::__future_base::_State_base::*)(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>&, bool&), std::__future_base::_State_base* const, std::reference_wrapper<std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()> >, std::reference_wrapper<bool> >(std::onc---Type <return> to continue, or q <return> to quit---
e_flag&, void (std::__future_base::_State_base::*&&)(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>&, bool&), std::__future_base::_State_base* const&&, std::reference_wrapper<std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()> >&&, std::reference_wrapper<bool>&&) (__once=...,
__f=<unknown type in /home/brodie/workspace/inverted_index/src/InvertedIndexMain, CU 0x0, DIE 0x3f48a>) at /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/mutex:819
#27 0x0000000000408333 in std::__future_base::_State_base::_M_set_result(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>, bool) (this=0x644838,
__res=..., __ignore_failure=false) at /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/future:362
#28 0x0000000000425f92 in std::__future_base::_Task_state<void ()>::_M_run() (this=0x644838) at /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/future:1271
#29 0x0000000000425c9c in std::packaged_task<void ()>::operator()() (this=0x644928) at /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/future:1379
#30 0x0000000000425ad8 in any_packaged<void>::execute (this=0x644920) at ThreadPool.hpp:27
#31 0x0000000000408743 in any_packaged_task::operator() (this=0x7ffff65dbdd0) at ThreadPool.hpp:40
#32 0x0000000000404baf in Worker::operator() (this=0x641120) at ThreadPool.hpp:109
#33 0x0000000000426068 in std::_Bind_simple<Worker ()>::_M_invoke<>(std::_Index_tuple<>) (this=0x641120) at /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/functional:1598
#34 0x0000000000425cb9 in std::_Bind_simple<Worker ()>::operator()() (this=0x641120) at /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/functional:1586
#35 0x0000000000425af6 in std::thread::_Impl<std::_Bind_simple<Worker ()> >::_M_run() (this=0x641108) at /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/thread:115
#36 0x00000036ec6b2a20 in std::(anonymous namespace)::execute_native_thread_routine (__p=<optimized out>) at ../../../../../libstdc++-v3/src/c++11/thread.cc:73
#37 0x00000036e9207d15 in start_thread (arg=0x7ffff65dc700) at pthread_create.c:308
#38 0x00000036e8ef246d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:114
最佳答案
在我看来,您的 mutex
类型实际上并未提供互斥。您还记得使用 -pthread
编译器标志吗?
关于C++ 11 unordered_map 段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14691781/
我已经使用 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
我是一名优秀的程序员,十分优秀!