Detailed gem5 analysis of how data races happen

And pass niters as a thread argument to all threading implementations...
otherwise every loop has to do a memory load from the global!
This commit is contained in:
Ciro Santilli 六四事件 法轮功
2020-06-05 06:00:05 +00:00
parent 619fef4b04
commit 0d5c7f5c4c
6 changed files with 162 additions and 19 deletions

View File

@@ -7,12 +7,11 @@
#include <sys/types.h>
#include <unistd.h>
unsigned long long niters;
unsigned long long global = 0;
pthread_mutex_t main_thread_mutex = PTHREAD_MUTEX_INITIALIZER;
void* main_thread(void *arg) {
(void)arg;
unsigned long long niters = *(unsigned long long *)arg;
unsigned long long i;
for (i = 0; i < niters; ++i) {
pthread_mutex_lock(&main_thread_mutex);
@@ -24,7 +23,7 @@ void* main_thread(void *arg) {
int main(int argc, char **argv) {
pthread_t *threads;
unsigned long long i, nthreads;
unsigned long long i, niters, nthreads;
/* CLI arguments. */
if (argc > 1) {
@@ -41,7 +40,7 @@ int main(int argc, char **argv) {
/* Action */
for (i = 0; i < nthreads; ++i)
pthread_create(&threads[i], NULL, main_thread, NULL);
pthread_create(&threads[i], NULL, main_thread, &niters);
for (i = 0; i < nthreads; ++i)
pthread_join(threads[i], NULL);
assert(global == nthreads * niters);