test: dynamic_thread: Fix race condition
test: dynamic_thread: Fix race condition

There is a race between k_sem_take() and k_object_access_grant() so it
is possible (especially when testing SMP) that the thread tries to take
the semaphore before the originating thread has had the chance to
grant it permission.

Signed-off-by: Carlo Caione <ca4506c8c654a4ccf75802e86b5d162c1e96f065@baylibre.com>

zephyrproject-rtos/zephyr,galak/zephyr,galak/zephyr,finikorg/zephyr,finikorg/zephyr,galak/zephyr,galak/zephyr,Vudentz/zephyr,Vudentz/zephyr,nashif/zephyr,nashif/zephyr,zephyrproject-rtos/zephyr,zephyrproject-rtos/zephyr,nashif/zephyr,Vudentz/zephyr,Vudentz/zephyr,finikorg/zephyr,galak/zephyr,finikorg/zephyr,Vudentz/zephyr,nashif/zephyr,zephyrproject-rtos/zephyr,nashif/zephyr,finikorg/zephyr,Vudentz/zephyr,zephyrproject-rtos/zephyr