线程安全问题 #852
Unanswered
bolanbujing
asked this question in
Q&A
线程安全问题
#852
Replies: 1 comment
-
struct_pack本身是线程安全的。但是你得保证没有人在同时修改struct和缓冲区
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
现有两个线程同时执行
void Block::Encode(std::vector<uint8_t>& out) const { block_header_.Verify(); out = struct_pack::serialize<struct_pack::sp_config::DISABLE_TYPE_INFO, std::vector<uint8_t>>(*this); }
然后在serialize里崩溃了
#0 0x7f82ae7d836f in operator new(unsigned long) (/lib64/libasan.so.5+0x10e36f) #1 0x6db025 in __gnu_cxx::new_allocator<unsigned char>::allocate(unsigned long, void const*) /opt/rh/devtoolset-9/root/usr/include/c++/9/ext/new_allocator.h:114 #2 0x6db025 in std::allocator_traits<std::allocator<unsigned char> >::allocate(std::allocator<unsigned char>&, unsigned long) /opt/rh/devtoolset-9/root/usr/include/c++/9/bits/alloc_traits.h:444 #3 0x6db025 in std::_Vector_base<unsigned char, std::allocator<unsigned char> >::_M_allocate(unsigned long) /opt/rh/devtoolset-9/root/usr/include/c++/9/bits/stl_vector.h:343 #4 0x6db025 in std::vector<unsigned char, std::allocator<unsigned char> >::_M_default_append(unsigned long) /opt/rh/devtoolset-9/root/usr/include/c++/9/bits/vector.tcc:635 #5 0x26da18a in std::vector<unsigned char, std::allocator<unsigned char> >::resize(unsigned long) /opt/rh/devtoolset-9/root/usr/include/c++/9/bits/stl_vector.h:937 #6 0x26da18a in void struct_pack::detail::resize<unsigned char>(std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned long) /data/gitlab/chain/deps/include/ylt/struct_pack/util.h:255 #7 0x26da18a in void struct_pack::serialize_to<1ul, std::vector<unsigned char, std::allocator<unsigned char> >, chain::core::Block>(std::vector<unsigned char, std::allocator<unsigned char> >&, chain::core::Block const&) /data/gitlab/chain/deps/include/ylt/struct_pack.hpp:156 #8 0x26db4e1 in std::vector<unsigned char, std::allocator<unsigned char> > struct_pack::serialize<1ul, std::vector<unsigned char, std::allocator<unsigned char> >, chain::core::Block>(chain::core::Block const&) /data/gitlab/chain/deps/include/ylt/struct_pack.hpp:249 #9 0x2687b9f in chain::core::Block::Encode(std::vector<unsigned char, std::allocator<unsigned char> >&) const /data/block.cpp:29
请问,struct_pack的编解码不保证线程安全吗
Beta Was this translation helpful? Give feedback.
All reactions