[PATCH 4/5] SMP01: possible CPU race when using byte arrays

Daniel Hellstrom daniel at gaisler.com
Thu Oct 31 13:58:53 UTC 2013


Switch to using 32-bit variable that works better on a
32-bit CPU. This does not solve the general SMP case
though, would perhaps better to use an atomic set
here.

Signed-off-by: Daniel Hellstrom <daniel at gaisler.com>
---
 testsuites/smptests/smp01/init.c   |    6 +++---
 testsuites/smptests/smp01/system.h |    2 +-
 testsuites/smptests/smp01/tasks.c  |    2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/testsuites/smptests/smp01/init.c b/testsuites/smptests/smp01/init.c
index 3e12726..eadb26a 100644
--- a/testsuites/smptests/smp01/init.c
+++ b/testsuites/smptests/smp01/init.c
@@ -43,11 +43,11 @@ rtems_task Init(
   locked_print_initialize();
 
   /* Put start of test message */
-  locked_printf( "\n\n***  SMP01 TEST ***\n" );
+  locked_printf( "\n\n***  SMP01 TEST %d ***\n", cpu_self );
 
   /* Initialize the TaskRan array */
   for ( i=0; i<rtems_smp_get_processor_count() ; i++ ) {
-    TaskRan[i] = false;
+    TaskRan[i] = 0;
   }
 
   /* Create and start tasks for each processor */
@@ -77,7 +77,7 @@ rtems_task Init(
   while (1) {
     allDone = true;
     for ( i=0; i<rtems_smp_get_processor_count() ; i++ ) {
-      if ( i != cpu_self && TaskRan[i] == false)
+      if ( i != cpu_self && TaskRan[i] == 0)
         allDone = false;
     }
     if (allDone) {
diff --git a/testsuites/smptests/smp01/system.h b/testsuites/smptests/smp01/system.h
index e360e37..5f2d5b7 100644
--- a/testsuites/smptests/smp01/system.h
+++ b/testsuites/smptests/smp01/system.h
@@ -42,7 +42,7 @@ rtems_task Test_task(
  *  Keep the names and IDs in global variables so another task can use them.
  */
 
-TEST_EXTERN volatile bool TaskRan[ CONFIGURE_SMP_MAXIMUM_PROCESSORS ];
+TEST_EXTERN volatile int TaskRan[ CONFIGURE_SMP_MAXIMUM_PROCESSORS ];
 
 void Loop( void );
 
diff --git a/testsuites/smptests/smp01/tasks.c b/testsuites/smptests/smp01/tasks.c
index 4eb81f1..7bd7cc4 100644
--- a/testsuites/smptests/smp01/tasks.c
+++ b/testsuites/smptests/smp01/tasks.c
@@ -35,7 +35,7 @@ rtems_task Test_task(
   locked_printf(" CPU %" PRIu32 " running Task %s\n", cpu_num, name);
 
   /* Set the flag that the task is up and running */
-  TaskRan[cpu_num] = true;
+  TaskRan[cpu_num] = 1;
 
 
   /* Drop into a loop which will keep this task on
-- 
1.7.0.4




More information about the devel mailing list