Listing 1Heres the source code for the benchmark program used to obtain the benchmark results. This program can run without source-code modifications under Windows 95, NT, and the On Time Win32-compatible embedded RTOS.
#include#include #include #define LOOPS 100000 HANDLE S1, S2; DWORD WINAPI ThreadA(LPVOID lpdwParam) { while (1){ WaitForSingleObject(S1, INFINITE); ReleaseSemaphore(S2, 1, NULL); } return 0; } DWORD main(void) { HANDLE H; DWORD ThreadID, T, i; S1 = CreateSemaphore(NULL, 0, 1, "BenchSema1"); S2 = CreateSemaphore(NULL, 0, 1, "BenchSema2"); H = CreateThread(NULL, 0, ThreadA, NULL, 0, &ThreadID); Sleep(100); printf("switching between two tasks %i times...\n", LOOPS); T = GetTickCount(); for (i=0; i<LOOPS; i++){ ReleaseSemaphore(S1, 1, NULL); WaitForSingleObject(S2, INFINITE); } T = GetTickCount() - T; printf("Time for %i loops: %i milliseconds\n", LOOPS, T); TerminateThread(H, 0); CloseHandle(H); CloseHandle(S1); CloseHandle(S2); printf("Hit return to terminate...\n"); getc(stdin); return 0; } Figure 3-This diagram illustrates creating a binary program image file with standard Win32 compilers and the On Time Embedded RTOS.