Fix tsan detected error in core/util/exec_on_stall_test.cc
Enforce mutex around access to test variable. PiperOrigin-RevId: 200078751
This commit is contained in:
parent
20a8e604e3
commit
530dc71d04
@ -16,6 +16,7 @@ limitations under the License.
|
|||||||
#include "tensorflow/core/util/exec_on_stall.h"
|
#include "tensorflow/core/util/exec_on_stall.h"
|
||||||
|
|
||||||
#include "tensorflow/core/platform/macros.h"
|
#include "tensorflow/core/platform/macros.h"
|
||||||
|
#include "tensorflow/core/platform/mutex.h"
|
||||||
#include "tensorflow/core/platform/test.h"
|
#include "tensorflow/core/platform/test.h"
|
||||||
|
|
||||||
namespace tensorflow {
|
namespace tensorflow {
|
||||||
@ -32,14 +33,24 @@ Chunk* NewChunk(int stall_seconds, std::function<void()> f) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(ExecuteOnStallTest, BothWays) {
|
TEST(ExecuteOnStallTest, BothWays) {
|
||||||
bool a_triggered = false;
|
mutex mu;
|
||||||
bool b_triggered = false;
|
bool a_triggered(false);
|
||||||
Chunk* a = NewChunk(1, [&a_triggered]() { a_triggered = true; });
|
bool b_triggered(false);
|
||||||
Chunk* b = NewChunk(1, [&b_triggered]() { b_triggered = true; });
|
Chunk* a = NewChunk(1, [&mu, &a_triggered]() {
|
||||||
|
mutex_lock l(mu);
|
||||||
|
a_triggered = true;
|
||||||
|
});
|
||||||
|
Chunk* b = NewChunk(1, [&mu, &b_triggered]() {
|
||||||
|
mutex_lock l(mu);
|
||||||
|
b_triggered = true;
|
||||||
|
});
|
||||||
delete a;
|
delete a;
|
||||||
Env::Default()->SleepForMicroseconds(2000000);
|
Env::Default()->SleepForMicroseconds(2000000);
|
||||||
|
{
|
||||||
|
mutex_lock l(mu);
|
||||||
EXPECT_FALSE(a_triggered);
|
EXPECT_FALSE(a_triggered);
|
||||||
EXPECT_TRUE(b_triggered);
|
EXPECT_TRUE(b_triggered);
|
||||||
|
}
|
||||||
delete b;
|
delete b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user