Add `volatile` specifier for the mapped memory area pointer to give 43/278743/2
authorAdam Michalski <a.michalski2@partner.samsung.com>
Mon, 25 Jul 2022 14:50:48 +0000 (16:50 +0200)
committerAdam Michalski <a.michalski2@partner.samsung.com>
Wed, 10 Aug 2022 12:16:00 +0000 (14:16 +0200)
a hint to the compiler that it cannot optimize any checks to it

Without this hint the compiler tends to optimize the synchronization
barrier as it thinks that if a variable is unchanged in the parent
process, it can optimize access to it and not perform the check each
time during the `while` loop which leads to deadlock (endless waiting).

Change-Id: I0a316b4e0d1546bc6864737c20c86601635fff2a

benchmark/gdbus.c
benchmark/libdbus.c
benchmark/pipe.c
benchmark/socket.c

index b9a02f7925085c726a641396080f6016a8e0a0d9..5c281ef47deb5f8355a7574a738107e5d82f822c 100644 (file)
@@ -256,7 +256,7 @@ void Measure_bandwidth(void)
        int returnp[nprocs/2][2];
        int pids[nprocs];
        int ready_fd;
-       char *ready_ptr;
+       volatile char *ready_ptr;
 
        ready_fd = shm_open("isready", O_CREAT | O_TRUNC | O_RDWR, 0666);
        if(ready_fd == -1)
@@ -359,7 +359,7 @@ void Measure_bandwidth(void)
 
                waitpid(pids[child], NULL, 0);
        }
-       ret = munmap(ready_ptr, sizeof(bool));
+       ret = munmap((void*)ready_ptr, sizeof(bool));
        if (ret != 0) {
                perror("munmap");
                exit(1);
index 84f1df79c15cbd6339d55c2fd7ab27542207f90c..2efa631e70231342193a01a6e20d922fac16d3c0 100644 (file)
@@ -213,7 +213,7 @@ void Measure_bandwidth(void)
        int returnp[nprocs/2][2];
        int pids[nprocs];
        int ready_fd;
-       char *ready_ptr;
+       volatile char *ready_ptr;
 
        ready_fd = shm_open("isready", O_CREAT | O_TRUNC | O_RDWR, 0666);
        if(ready_fd == -1)
@@ -318,7 +318,7 @@ void Measure_bandwidth(void)
 
                waitpid(pids[child], NULL, 0);
        }
-       ret = munmap(ready_ptr, sizeof(bool));
+       ret = munmap((void*)ready_ptr, sizeof(bool));
        if (ret != 0) {
                perror("munmap");
                exit(1);
index f0b39073d980df32a3b9bf3fbe5ba655b284cd8f..1d46d8fb5618587a135e85998afad8411fbaf9b8 100644 (file)
@@ -137,7 +137,7 @@ void Measure_bandwidth(void)
        int p[nprocs/2][2];
        int pids[nprocs];
        int ready_fd;
-       char *ready_ptr;
+       volatile char *ready_ptr;
 
        ready_fd = shm_open("isready", O_CREAT | O_TRUNC | O_RDWR, 0666);
        if(ready_fd == -1)
@@ -251,7 +251,7 @@ void Measure_bandwidth(void)
                waitpid(pids[child], NULL, 0);
        }
 
-       ret = munmap(ready_ptr, sizeof(bool));
+       ret = munmap((void*)ready_ptr, sizeof(bool));
        if (ret != 0) {
                perror("munmap");
                exit(1);
index 01d24d3e7ef11c1ae0db077c575cb24878597af1..2d3ed7adab472d0cf638a64f8060e93dd1b2bcf8 100644 (file)
@@ -137,7 +137,7 @@ void Measure_bandwidth(void)
        int fd[nprocs/2][2];
        int pids[nprocs];
        int ready_fd;
-       char *ready_ptr;
+       volatile char *ready_ptr;
 
        ready_fd = shm_open("isready", O_CREAT | O_TRUNC | O_RDWR, 0666);
        if(ready_fd == -1)
@@ -251,7 +251,7 @@ void Measure_bandwidth(void)
 
                waitpid(pids[child], NULL, 0);
        }
-       ret = munmap(ready_ptr, sizeof(bool));
+       ret = munmap((void*)ready_ptr, sizeof(bool));
        if (ret != 0) {
                perror("munmap");
                exit(1);