Closed rochus-keller closed 2 years ago
I found the following:
public class Test5 {
private static void worker(object o) {
System.Console.WriteLine("hello from worker");
}
static void begin() {
System.Console.WriteLine("start test");
System.Threading.Thread t = new System.Threading.Thread(worker);
t.Start();
t.Join(); // hangs in join
System.Console.WriteLine("end test");
}
static Test5() {
// no effect: System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(typeof (object).TypeHandle);
// no effect: begin();
System.Console.WriteLine("start test");
System.Threading.Thread t = new System.Threading.Thread(worker);
t.Start();
t.Join(); // hangs in join
System.Console.WriteLine("end test");
}
static void Main(string[] args) {
/*
System.Console.WriteLine("hello from Main");
System.Console.WriteLine("start test");
System.Threading.Thread t = new System.Threading.Thread(worker);
t.Start();
t.Join(); // works
System.Console.WriteLine("end test");
*/
}
}
This is a minimal C# application which is able to demonstrate the effect. Thread.Join() uses assumingly the same low-level function as bthread_wait(). If we call Join() in the static constructor the thread starts but doesn't run its body; so we aparently cannot use static constructors as the "begin" part of a module - the system doesn't seem to be working properly at this point.
Fixed with commit 18e7d0dc2c69adbb; the issue was indeed related to the static constructor; apparently it is a bad idea to map Oberon module begin sections to static constructors; in the present case the thread system seems to be in an unknown state causing the strange observations. Since I moved module begin to a dedicated method called via import dependency chain NAppGUI threads work seamless with Mono.
The NAppGUI Fractals example now works fine on Linux and Windows when run from Mono. There is still an issue on macOS though; the NAppGUI app seems to hang in osmain just after window_show; will be traced in a separate issue.
Even the most trivial test case hangs:
This just prints
to the console and then waits forever; I found an old Mono bug report which seems to describe this behaviour: https://bugzilla.xamarin.com/15/15695/bug.html; same behaviour in both the Boehm and Sgen version of Mono; still researching. Apparently the worker function is not run (we don't get output from it); no wonder we wait on bthread_wait.
The generated IL code doesn't look suspicious from my point of view:
When the same code is exported to C and run everything works as expected.