Closed yuThomas closed 1 year ago
- What compiler are you using?
- Can you please provide a complete example?
sorry too late, example as below:
int main(int argc, char* argv)
{
moodycamel::ConcurrentQueue<nlohmann::json> que;
std::vector
auto *data = new nlohmann::json;
(*data)["ac"] = "1";
(*data)["state"] = "1";
// more else key-value items
for( int i=0; i<3; i++ )
{
vecP.emplace_back(moodycamel::ProducerToken(que));
std::thread th([&]{
std::vector<nlohmann::json*> dataBuck(100);
size_t num;
for(;;)
{
num = que.try_dequeue_bulk_from_producer(vecP[i], &dataBuck[0], 100);
if ( num > 0 )
{
for ( size_t j=0; j<num; j++)
{
// do something else
}
}
}
});
th.detach();
}
for( int i=0; i<8; i++)
{
std::thread th([=,&que]{
for(;;)
{
std::hash<std::string> h;
que.enqueue(vecP[h(data->dump()+ std::to_string(i))/3], data);
}
});
th.detach();
}
getchar();
return 0;
}
This error is not related to the library at all.
std::hash<std::string> h;
que.enqueue(vecP[h(...) / 3], data);
You want %
not /
here to convert the hash into a vector index. Even better would be
vecP[h(...) % vecP.size()]
This error is not related to the library at all.
std::hash<std::string> h; que.enqueue(vecP[h(...) / 3], data);
You want
%
not/
here to convert the hash into a vector index. Even better would bevecP[h(...) % vecP.size()]
sorry to give the wrong code ,actually, i do use % instead of /
Can you then please share a complete working example, including main and everything?
@yuThomas Any updates?
Description
string_t dump(const int indent = -1, const char indent_char = ' ', const bool ensure_ascii = false, const error_handler_t error_handler = error_handler_t::strict) const
cause "assertion
false
" coredumpReproduction steps
Expected vs. actual results
Expected: a normal json string or empty
actual results: assertion failed
Minimal code example
No response
Error messages
Compiler and operating system
linux 5.4.17-2011.6.2.el7uek.x86_64
Library version
3.10.5
Validation
develop
branch is used.