sys:posix:pthread added check to avoid array out of bound access

This PR adds checks to avoid acces to `pthread_sched_threads[]` with possibly negative values