1 // See also https://bugs.kde.org/show_bug.cgi?id=322621
5 #include "../../helgrind/helgrind.h"
8 static pthread_t ls_thread
;
9 static pthread_barrier_t ls_barrier
;
13 #define LS_BUF_SIZE (1024*1024)
16 void fill_buffer(int buf
)
19 std::cerr
<< "Fill " << buf
<< "\n";
20 for (int i
= 0; i
< LS_BUF_SIZE
; i
++)
23 std::cerr
<< "Fill " << buf
<< " done\n";
26 int read_buffer(int buf
)
29 std::cerr
<< "Read " << buf
<< "\n";
31 for (int i
= 0; i
< LS_BUF_SIZE
; i
++)
32 res
+= ls_buf
[buf
][i
];
34 std::cerr
<< "Read " << buf
<< " done\n";
38 void *the_thread(void *ptr
)
42 for (int i
= 0; i
< NR_RUNS
; i
++) {
47 std::cerr
<< "Aux at barrier " << i
<< "\n";
48 pthread_barrier_wait(&ls_barrier
);
50 std::cerr
<< "Aux after barrier " << i
<< "\n";
60 VALGRIND_HG_DISABLE_CHECKING(&std::cerr
, sizeof(std::cerr
));
62 ls_buf
[0] = new char[LS_BUF_SIZE
];
63 ls_buf
[1] = new char[LS_BUF_SIZE
]; // second buffer only when multithreaded
65 pthread_barrier_init(&ls_barrier
, NULL
, 2);
68 pthread_attr_init(&attr
);
69 pthread_attr_setdetachstate(&attr
, PTHREAD_CREATE_JOINABLE
);
70 pthread_create(&ls_thread
, &attr
, the_thread
, NULL
);
71 pthread_attr_destroy(&attr
);
74 for (int i
= 0; i
< NR_RUNS
; i
++) {
75 std::cerr
<< "Main at barrier " << i
<< "\n";
76 pthread_barrier_wait(&ls_barrier
);
77 std::cerr
<< "Main after barrier " << i
<< "\n";
79 (void)read_buffer(buf
);
82 pthread_join(ls_thread
,NULL
);
83 pthread_barrier_destroy(&ls_barrier
);
84 delete[] ls_buf
[1]; // second buffer only when multithreaded