I wrote one software that uses ThreadPool for multithreading.
ThreadPool.SetMinThreads(128, 128);
ThreadPool.SetMaxThreads(512, 512);
for (int i = 0; i < 40; i++)
{
ThreadPool.QueueUserWorkItem(_ =>
{
Console.Write("!");
Thread.Sleep(1000);
Console.Write(".");
}, null);
}
Inside each thread I perform blocking network operations(work with http). Software designed around blocking network model and I cannot move to non blocking 1 threaded I/O.
It works perfect on windows platform, I can use 128-512 threads per one core without any issues, all work as it should work. But when I moved to mono, I saw some really strange behaviour. I cannot make mono run many threads per one CPU core, max I can get - 1 thread per core, doesn't matter what I do specify in SetMinThreads/SetMaxThreads.
tried under Linux with .NET 4/4.5, MONO version 3.2.1 and some older version on my previous system. Btw, plain threading code works well, for example this gives desired result:
for (int i = 0; i < 20; i++)
{
var t = new Thread(_ => {
Console.Write("!");
Thread.Sleep(1000);
Console.Write(".");
});
t.Start();
}
Why don't you use a combination of these stuff (like: Asyn, MultiThreading, Parallel) if multi threading is not enough for your work !? I think these may be helpful for you : http://mono-for-android.1047100.n5.nabble.com/Task-Parallel-Framework-issues-td5711359.html stackoverflow.com/questions/5717059/implementation-of-task-in-monodroid http://blog.errorok.com/2012/08/09/268/
We've also experimented alot with mono and looks that following helps:
We're using both options and mono on linux acting quite fast( comparable to .net on windows )