Download Latest Version chordease-1.0.14.000-bin-x64.zip (1.1 MB)
Email in envelope

Get an email when there's a new version of ChordEase

Home / tools / ThreadBoost
Name Modified Size InfoDownloads / Week
Parent folder
readme.txt 2015-06-09 1.6 kB
ThreadBoost NET.zip 2015-06-09 11.6 kB
Totals: 2 Items   13.2 kB 0
This is the source code for ThreadBoost.dll, which ChordEase uses to boost the priority of MIDI callbacks in Windows Vista and above. The DLL is loaded in CChordEaseApp::BoostThreads in ChordEase.cpp. ChordEase will run without this DLL, but latency may be increased, due to MIDI threads potentially being blocked by the GUI thread.

In Vista and later, MIDI input callbacks run at priority 0 instead of 15. Consequently input callbacks no longer preempt normal threads, including the GUI thread, and this can increase the latency of our response to MIDI input, particularly if all CPUs are saturated with normal priority work. We solve this by loading a DLL that catches thread launching, and boosts any threads having priority 0 (normal) to priority 1 (above normal).

The DLL's entire source code is shown below. It takes advantage of the fact that all DLLs are called when a thread is created, and simply boosts all subsequently created threads from normal priority to above normal priority. The GUI thread is unaffected since it's already been created by the time this DLL is loaded.

You can also obtain this DLL from any of the ChordEase distributions if you don't want to build it yourself.

BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
					 )
{
	if (ul_reason_for_call == DLL_THREAD_ATTACH) {
		HANDLE	hThread = GetCurrentThread();
		if (GetThreadPriority(hThread) == THREAD_PRIORITY_NORMAL)
			SetThreadPriority(hThread, THREAD_PRIORITY_ABOVE_NORMAL);
	}
	return TRUE;
}
Source: readme.txt, updated 2015-06-09