操作系统学习笔记 - 线程管理 Win32 Fibonacci计算
#include <windows.h> #include <stdio.h> DWORD FiboArray[48]; DWORD WINAPI Fibo (LPVOID Param){ DWORD N = *(DWORD*)Param; FiboArray [0] = 0; FiboArray [1] = 1; for (int i = 2; i < N; i++){ FiboArray[i] = FiboArray[i - 1] + FiboArray[i - 2]; } return 0; } int main (int argc, char *argv[]){ DWORD ThreadId; HANDLE ThreadHandle; int param; if (argc != 2){ printf ("Need ONE unsigned integer, 0-47 (inclusive)"); return -1; } param = atoi(argv[1]); if (param < 0 || param > 47){ printf ("Need ONE integer, ranging 0 to 47 inclusive."); return -1; } ThreadHandle = CreateThread( NULL, 0, Fibo, ¶m, 0, &ThreadId); if (ThreadHandle != NULL) { WaitForSingleObject(ThreadHandle, INFINITE); CloseHandle(ThreadHandle); for (int i = 0; i <= param; i++){ printf ("%d ", FiboArray[i]); } printf ("\n"); } }