Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions testing/ostest/sched_thread_local.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Biancaa-R all common code (that needs to work on old microcontrollers) should follow the C89. Please read the https://nuttx.apache.org/docs/latest/contributing/coding_style.html for more info about the NuttX coding style

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other detail: g_ is used when you are defining a global variable, that is not the case here since you are defining it inside a function

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Biancaa-R all common code (that needs to work on old microcontrollers) should follow the C89. Please read the https://nuttx.apache.org/docs/latest/contributing/coding_style.html for more info about the NuttX coding style

Sure sir Ill read it and modify accordingly.

if (id == 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try to print the "id" ? I think it never will be 0, if I'm not wrong (and I could be wrong) it starts from 1.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it does start from 0 based on the attached log (it is printed a few times)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it does start from 0 based on the attached log (it is printed a few times)

Yes.

{
g_first_thread_addr = (void *)&g_tls_int;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

}
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 */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this comment.

}

printf("thread_func[%d]: setting value_short (at 0x%p) to %d\n",
id, &g_tls_short, value_short + id);

Expand Down Expand Up @@ -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 */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this comment.

}

for (i = 0; i < TEST_THREADS; i++)
Expand Down Expand Up @@ -227,6 +247,16 @@ void sched_thread_local_test(void)
printf("sched_thread_local_test: pthread_barrier_destroy failed, "
"status=%d\n", status);
}

/* Confirm main thread still have initial values */

if (g_tls_int != INIT_VALUE)
{
printf("sched_thread_local_test: ERROR: Main thread TLS corrupted!\n");
ASSERT(false);
}

printf("sched_thread_local_test: Main thread isolation confirmed.\n");
}

#endif /* CONFIG_SCHED_THREAD_LOCAL */
Loading