widgets: check if thread is valid before running pthread_cancel

Fixes segfault when widget shared objects are missing.