-
Notifications
You must be signed in to change notification settings - Fork 295
Conversation
Signed-off-by: kamilsa <[email protected]>
Signed-off-by: kamilsa <[email protected]>
bar.wait(); | ||
{ | ||
std::unique_lock<std::mutex> lk(m); | ||
cv.wait(lk, [&] { return processed; }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That will wait forever, if notify_all
is called before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? This is equivalent to while (!pred()) { wait(lock); }
, so it will unlock after the observable is completed.
Edit: it will wait forever indeed because it will not be woken up
@@ -279,7 +286,10 @@ namespace integration_framework { | |||
tx_list); | |||
|
|||
// make sure that the first (stateless) status is come | |||
bar.wait(); | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code block is redundant.
@@ -265,7 +268,11 @@ namespace integration_framework { | |||
statuses.push_back(*std::static_pointer_cast< | |||
shared_model::proto::TransactionResponse>(s)); | |||
}, | |||
[&bar] { bar.wait(); }); | |||
[&cv, &m, &processed] { | |||
std::lock_guard<std::mutex> lock(m); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lock seems redundant here, what is its purpose? processed
cannot be modified concurrently because on_complete is called once only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to https://en.cppreference.com/w/cpp/thread/condition_variable it is needed
Signed-off-by: kamilsa <[email protected]>
3aa5f29
to
4a30e0e
Compare
SonarQube analysis reported 1 issue
|
* Fix send tx sequence method Signed-off-by: kamilsa <[email protected]> * Add lock guard Signed-off-by: kamilsa <[email protected]> * Remove scope Signed-off-by: kamilsa <[email protected]>
Signed-off-by: kamilsa [email protected]
Description of the Change
Due to unclear reasons boost::barrier throws segfault in send tx sequence test (once out from 100 runs on average). To avoid that it was replaced with std::condition_variable.
Benefits
No segfaults are thrown anymore(test was executed ~2000 times)
Possible Drawbacks
Inconsistency with
sendTx
method which still usesboost::barrier