mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 21:03:12 +00:00
Use a std::atomic in test_iothread
Reduces noise from thread-sanitizer
This commit is contained in:
parent
e8d90dbf4b
commit
cb70ac6932
1 changed files with 4 additions and 3 deletions
|
@ -25,6 +25,7 @@
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#include <wctype.h>
|
#include <wctype.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <atomic>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -512,7 +513,7 @@ static void test_tokenizer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Little function that runs in a background thread, bouncing to the main.
|
// Little function that runs in a background thread, bouncing to the main.
|
||||||
static int test_iothread_thread_call(int *addr) {
|
static int test_iothread_thread_call(std::atomic<int> *addr) {
|
||||||
int before = *addr;
|
int before = *addr;
|
||||||
iothread_perform_on_main([=]() { *addr += 1; });
|
iothread_perform_on_main([=]() { *addr += 1; });
|
||||||
int after = *addr;
|
int after = *addr;
|
||||||
|
@ -526,7 +527,7 @@ static int test_iothread_thread_call(int *addr) {
|
||||||
|
|
||||||
static void test_iothread(void) {
|
static void test_iothread(void) {
|
||||||
say(L"Testing iothreads");
|
say(L"Testing iothreads");
|
||||||
std::unique_ptr<int> int_ptr = make_unique<int>(0);
|
std::unique_ptr<std::atomic<int>> int_ptr = make_unique<std::atomic<int>>(0);
|
||||||
int iterations = 50000;
|
int iterations = 50000;
|
||||||
int max_achieved_thread_count = 0;
|
int max_achieved_thread_count = 0;
|
||||||
double start = timef();
|
double start = timef();
|
||||||
|
@ -541,7 +542,7 @@ static void test_iothread(void) {
|
||||||
|
|
||||||
// Should have incremented it once per thread.
|
// Should have incremented it once per thread.
|
||||||
if (*int_ptr != iterations) {
|
if (*int_ptr != iterations) {
|
||||||
say(L"Expected int to be %d, but instead it was %d", iterations, *int_ptr);
|
say(L"Expected int to be %d, but instead it was %d", iterations, int_ptr->load());
|
||||||
}
|
}
|
||||||
|
|
||||||
say(L" (%.02f msec, with max of %d threads)", (end - start) * 1000.0,
|
say(L" (%.02f msec, with max of %d threads)", (end - start) * 1000.0,
|
||||||
|
|
Loading…
Reference in a new issue