Skip to content

Conversation

@Superpiffer
Copy link
Contributor

In multithreading .NET 4.8 applications, sometimes in Session finalizer the method c_api.TF_DeleteSession find f.Status static instance already disposed for some reason. No problem for .NET 6 application or with a single thread. (#912)

In multithreading .NET 4.8 applications, sometimes in Session finalizer the method c_api.TF_DeleteSession find f.Status static instance already disposed for some reason. No problem for .NET 6 application or with a single thread.
@Oceania2018 Oceania2018 merged commit 43625ab into SciSharp:master Feb 4, 2023
@Oceania2018
Copy link
Member

@Superpiffer Do you think it will work if I change to below

if (tf.Status == null || tf.Status.Handle.IsInvalid)
{
    c_api.TF_DeleteSession(handle, c_api.TF_NewStatus());
}
else
{
    c_api.TF_DeleteSession(handle, tf.Status.Handle);
}

@Superpiffer
Copy link
Contributor Author

@Superpiffer Do you think it will work if I change to below

if (tf.Status == null || tf.Status.Handle.IsInvalid)
{
    c_api.TF_DeleteSession(handle, c_api.TF_NewStatus());
}
else
{
    c_api.TF_DeleteSession(handle, tf.Status.Handle);
}

I think so, maybe that's ok as a "last resort" in my use case, also preserving the previous behaviour. I can test it on monday.
The problem is that I'm not familiar with ThreadLocal and I don't know why tf.Status is disposed before all the session threads are stopped and ONLY on .NET 4.8...

@Superpiffer
Copy link
Contributor Author

@Oceania2018 I tried and I have the same problem:
image
image

@SanftMonster
Copy link
Collaborator

Is there any code like using(session.as_default()){ } in your code? Sometimes annoying things happens when I use the scope with using.

@Superpiffer
Copy link
Contributor Author

Is there any code like using(session.as_default()){ } in your code? Sometimes annoying things happens when I use the scope with using.

No, I cannot use using because I need to reuse the same session during my processing. You can find a sample code here: #912

Also I made a new PR with a possible solution: #978

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants