My problem is probably as simple as not checking if the threads create fails, but what is the best way to do this?
You can simply just check for the return value of the ->create() method:
if (! ($threads_list[$loop] = threads->create(\&worker_thread, $loop))) {
# Failed to create thread
....
}
Also any idea to reduce eliminate the failure in the first place
There will probably be warning messages issued which may give more info. You'll need to 'catch' them (run with stderr to a log file) see.
