linguini1 commented on code in PR #3412:
URL: https://github.com/apache/nuttx-apps/pull/3412#discussion_r2849575660


##########
testing/ostest/sched_thread_local.c:
##########
@@ -159,6 +176,9 @@ void sched_thread_local_test(void)
     {
       printf("sched_thread_local_test: pthread_barrier_init failed, "
              "status=%d\n", status);
+      ASSERT(false);
+
+      /* the threads will call pthread_barrier_wait on an invalid object */

Review Comment:
   Remove this comment.



##########
testing/ostest/sched_thread_local.c:
##########
@@ -114,6 +114,23 @@ static void *thread_func(void *parameter)
       ASSERT(false);
     }
 
+  printf("thread_func[%d]: TLS addr=%p\n", id, &g_tls_int);
+
+  /* In a broken system, all threads might point to the same static address */
+
+  static void *g_first_thread_addr = NULL;
+  if (id == 0)
+    {
+      g_first_thread_addr = (void *)&g_tls_int;
+    }
+  else if (g_first_thread_addr == (void *)&g_tls_int)
+    {
+      printf("ERROR: Thread %d shares address with Thread 0\n", id);
+      ASSERT(false);
+
+      /* Checking 0 and other addresses */

Review Comment:
   Remove this comment.



##########
testing/ostest/sched_thread_local.c:
##########
@@ -114,6 +114,23 @@ static void *thread_func(void *parameter)
       ASSERT(false);
     }
 
+  printf("thread_func[%d]: TLS addr=%p\n", id, &g_tls_int);
+
+  /* In a broken system, all threads might point to the same static address */
+
+  static void *g_first_thread_addr = NULL;
+  if (id == 0)

Review Comment:
   I believe it does start from 0 based on the attached log (it is printed 
there)



##########
testing/ostest/sched_thread_local.c:
##########
@@ -114,6 +114,23 @@ static void *thread_func(void *parameter)
       ASSERT(false);
     }
 
+  printf("thread_func[%d]: TLS addr=%p\n", id, &g_tls_int);
+
+  /* In a broken system, all threads might point to the same static address */
+
+  static void *g_first_thread_addr = NULL;
+  if (id == 0)
+    {
+      g_first_thread_addr = (void *)&g_tls_int;

Review Comment:
   What happens when the threads are released from the synchronized barrier? 
There is no guarantee that the first thread will set `g_first_thread_addr` 
before it is read by other threads. In fact, in your attached log, thread 2 
starts first.
   
   This check doesn't work.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to