Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1016 B

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <windows.h>
  5. LPVOID Fibers[4];
  6. VOID
  7. FiberRoutine(
  8. LPVOID lpParameter
  9. )
  10. {
  11. DWORD FiberId;
  12. FiberId = (DWORD)GetFiberData();
  13. printf("Init: In Fiber %d, %x Param %d\n",FiberId,GetCurrentFiber(),lpParameter);
  14. while(1) {
  15. printf("In Fiber %d %d\n",FiberId,(DWORD)GetFiberData() );
  16. Sleep(10);
  17. if ( FiberId == 3 ) {
  18. SwitchToFiber(Fibers[0]);
  19. }
  20. else {
  21. SwitchToFiber(Fibers[FiberId+1]);
  22. }
  23. }
  24. }
  25. int _cdecl main(void)
  26. {
  27. DWORD IdealProcessor;
  28. IdealProcessor = SetThreadIdealProcessor(GetCurrentThread(),MAXIMUM_PROCESSORS);
  29. printf("IdealProcessor %d\n",IdealProcessor);
  30. Fibers[0] = ConvertThreadToFiber((LPVOID)0);
  31. Fibers[1] = CreateFiber(0,FiberRoutine,(LPVOID)1);
  32. Fibers[2] = CreateFiber(0,FiberRoutine,(LPVOID)2);
  33. Fibers[3] = CreateFiber(0,FiberRoutine,(LPVOID)3);
  34. FiberRoutine((LPVOID)99);
  35. return 1;
  36. }