im deep diving in threading for my custom thread pool implementation.
My plan is the following when connecting big servers:
Im crafting a tcp/udp/named/anonymous pipe library.
1 thread running on each core waiting for input (keyword thread affinity) 1 socket per thread(abstracted as a stream to support named pipes)
1 thread running on each core sending data (keyword thread affinity) 1 socket per thread(abstracted as a stream to support named pipes)
Result on 4 core server should be: (Abstracted as a interface ISequentialDataSource, ISequentialDataSink)
Core 0 => SendLoop, ReceiveLoop, ReceiveDeserializationLoop
Core 1 => SendLoop, ReceiveLoop, ReceiveDeserializationLoop
Core 2 => SendLoop, ReceiveLoop, ReceiveDeserializationLoop
Core 3 => SendLoop, ReceiveLoop, ReceiveDeserializationLoop
My theory is that i have the best data transfer rate when doing it like that.
https://github.com/dotnet/runtime/blob/main/docs/design/coreclr/botr/threading.md
Outlines that a c# thread does NOT map to a real thread. :'(
That strikes my plan :p
The native methods to support this behavior are there:
windows: https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setthreadaffinitymask
(I also read about ProcessingThread. It supports assigning the affinity but these threads do not map to the Threading.Threads. Those ProcessingThreads fetched can be fetched and configured using Process.Threads.)
linux: https://man7.org/linux/man-pages/man3/pthread_setaffinity_np.3.html
android: (ignored, this is for servers. maybe there is also pthreads for android... will investigate)
Is it possible to tie a managed thread to a specific core? Or is there any way to find the ProcessThread of a Threading.Thread? (And is it then guranteed to only handle the one thread or what will i tie to a processor then...)
This will be open source(MIT license): https://github.com/christopher-vonblum/RadFramework.Libraries
mfg, Christopher
Ps. Related and unsolved:
How to start a thread on a specific core?
How can I set processor affinity to a thread or a Task in .NET?
How to set the processor affinity of a managed thread?
Set thread processor affinity in Microsoft .Net
Help Microsoft :p