Add thread safe set. Fix destroy device error. Fix unit test.