Fix multi-threaded crash.

The truth-value handling code had a subtle rce condition involving the handling of dereferences of the shared_ptr, leading to crashes.  This is now fixed.