You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Embedded Mono hangs when using native threads #16192
Embedded mono hangs when using native threads to call into a mono function that allocates semi-large chunks of memory. Fails for mono 5.20.1.34 and 6.0.0.319, but works for 5.18.0.268.
The demo contains a simple C# function that allocates a memory block.
publicvoidFoo(){for(inti=1;i<=10;i++){Console.WriteLine(String.Format("Allocate {0} of 10",i));byte[]pixels=newbyte[1000000];// size affects how soon the thread hangs}Console.WriteLine("Done");return;}
This function is called from managed code (c++) in different threads, but each call completes before the next.
Current Behavior
The output of the test project is:
This should call Foo a hundred times, but hangs...
call Foo 0
Allocate 1 of 10
Allocate 2 of 10
Allocate 3 of 10
Allocate 4 of 10
Allocate 5 of 10
Allocate 6 of 10
Allocate 7 of 10
Allocate 8 of 10
Allocate 9 of 10
Allocate 10 of 10
Done
call Foo 1
Allocate 1 of 10
Allocate 2 of 10
Allocate 3 of 10
Allocate 4 of 10
Allocate 5 of 10
Allocate 6 of 10
Allocate 7 of 10
Allocate 8 of 10
When called from different threads it will hang after some time.
When called from a single thread it can go on forever.
I notice that the size of memory allocation in the c# code matters.
@krixkrix thanks for verifying. It means it's an issue in our new thread suspension mechanism. For now you can use MONO_THREADS_SUSPEND=preemptive as a workaround, in the long-term we have to fix this.
It seems I'm still having this problem. Mono is embedded into uWSGI, and the env var MONO_THREADS_SUSPEND=preemptive does help it to get through, without it it just hangs forever.
The app was compiled in a 6.8.0 env and running in a 6.12.0 env.
Activity
lewurm commentedon Aug 19, 2019
does running with
MONO_THREADS_SUSPEND=preemptivefixes your issue? we switched tohybridrecently.krixkrix commentedon Aug 22, 2019
Yes, actually it does.
So what does this mean, is it recommended or deprecated to do it this way?
lewurm commentedon Aug 23, 2019
@krixkrix thanks for verifying. It means it's an issue in our new thread suspension mechanism. For now you can use
MONO_THREADS_SUSPEND=preemptiveas a workaround, in the long-term we have to fix this./cc @lambdageek
krixkrix commentedon Aug 26, 2019
So is
MONO_THREADS_SUSPEND=preemptivesupported and tested, so it's safe to use or should I stick with mono 5.18 which works for me so far?jaykrell commentedon Aug 26, 2019
Yes. MONO_THREADS_SUSPEND=preemptive makes it work like old releases.
It is not deprecated.
thaystg commentedon Sep 16, 2019
Using MONO_THREADS_SUSPEND=hybrid or coop we get the hang.
[threading] embedded mono hangs
[threading] embedded mono hangs (#16907)
Bump to mono/mono@18920a83 (#3753)
Bump to mono/mono@18920a83 (#3753)
[threading] embedded mono hangs (mono/mono#16907)
Evengard commentedon Feb 12, 2023
It seems I'm still having this problem. Mono is embedded into uWSGI, and the env var
MONO_THREADS_SUSPEND=preemptivedoes help it to get through, without it it just hangs forever.The app was compiled in a 6.8.0 env and running in a 6.12.0 env.