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

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