move the thread-check code from train_from_dataset to a single function add UT for the thread check function