C # How to increase the likelihood that there will be no context switch in a particular section of code?

I have a critical piece of code in my application. I made a thread that runs it. The highest priority is what I could do.

Are there any suggestions on how to make part of the code run in this thread interrupt as little as possible (less context switch)?

The code is not complicated. I replaced all method calls with inline code, and I don't use anything high level (like LINQ). Most operations are arithmetic. There is only one string comparison (I am thinking about how to get rid of it). Half math with ints and half with doubles.

The code is x86.NET 4 C #. Powered by a single Xenon X3450 W2008R2. One application server.

(Unfortunately, the data comes from a 3d API that does not support x64 (I hate it!))

I would appreciate a quick discussion with experienced developers.

PS The server does not have a swap file, so hard page errors will not be executed (without unwanted I / O).

+3
source share
2 answers

, , - . , LINQ ( LINQ-to-objects, LINQ-to-SQL -, !). .. .

, , - , - . , . SetPriorityClass, ABOVE_NORMAL_PRIORITY_CLASS ( , ), .

, ( , (, , -) ). , , . , . , , , , , .

, , . , , , , !

+2

WINAPI, SetThreadPriority THREAD_PRIORITY_TIME_CRITICAL ( THREAD_PRIORITY_HIGHEST).

, ( ).

- ( ). , , , I/O ( ).

+1

Source: https://habr.com/ru/post/1750854/


All Articles