Closed ihowell closed 2 years ago
Hi @ihowel, thanks for spotting this!
Perhaps is better to allocate on TF_Status per model, as suggested by @ljn917 here.
@serizba Do you mind me having a PR to fix, i.e. adding a per model TF_Status? The global status will be used for eager ops only. There were so many people trying to build cppflow into a dll and having the deinitialuzation order fiasco.
@ljn917 Yeah sure! This way we'll fix all related issues.
Thanks!
Fixes #131
When creating a static version of a reference to a
cppflow::model
, there becomes an error when destructing, due to thecontext::get_status()
method using athread_local
status. While this is done normally for performance gains and is fine in most places. However, when the program is exiting, it first destructsthread_local
objects and thenstatic
ones. This leads tolocal_tf_status
containing anullptr
instead of a pointer to aTF_Status
object. Therefore,TF_DeleteSession(sess, status)
fails because it access*status
. The simplest fix is to not re-use this status object in the destructor of the session and instead make a new, non-thread_local
status instead.