threads: check for error when creating and joining threads