I am investigating the possibility of employing a .NET compiled MATLAB assembly (obtained using the Matlab Compiler Runtime) to perform simultaneous (in a multithreaded fashion) execution of several pieces of code.
My code reads
Thread t = new Thread(new ThreadStart(
() =>
{
dotnetclass AClass_1 = new dotnetclass();
Stopwatch sw = new Stopwatch();
sw.Start();
AClass_1.math_on_numbers(2, a, b);
sw.Stop();
Console.WriteLine("Elapsed (1): " + sw.Elapsed);
}));
Thread t2 = new Thread(new ThreadStart(
() =>
{
dotnetclass AClass_2 = new dotnetclass();
Stopwatch sw = new Stopwatch();
sw.Start();
AClass_2.math_on_numbers(2, a, b);
sw.Stop();
Console.WriteLine("Elapsed (2): " + sw.Elapsed);
}));
t.Start();
t2.Start();
where dotnetclass is defined in a MATLAB .NET assembly, and the function math_on_numbers performs some dummy mathematical operation and sleeps 3 seconds before returning.
Executing the above code, I observe the "Elapsed (1)" message after 3 seconds, and the "Elapsed (2)" message after 6 seconds. This would make me think that concurrent calls to the MATLAB runtime will always be queued in a single-threaded fashion.
My questions:
Is there a way to allow multithreading in this scenario?
In other frameworks (I'm especially interested in a Java environment), would this limitation still occur?