Add dynamic pthread support
These changes were taken from: https://git.beagleboard.org/beagleconnect/zephyr/zephyr/-/commit/407d971e00885616dd1f26037a3ec6a8125c7b57
This is also needed for greybus-for-zephyr and my GSoC application
Signed-off-by: Ayush Singh ayushsingh1325@gmail.com