Fiber: 讓windows可以模擬linux的thread

ConvertThreadToFiber 最一開始沒有浮點數運, 因此後來有Ex版

CreateFiber: 在fiber內create fiber SwitchToFiber: 用來呼叫要switch的thread addr

Fiber本身有scheduling,但和Windows的無關, 可以full control thread要拿到CPU time才能run 必須call swirch to fiber指定其中一條, fiber才會跑起來

Distroy fiber DeleteFiber可以砍其他fiber,不能自殺 可用ConvertFiberToThread來自殺, 會把自己的memory清乾淨

Storage data between Fiber FLSAlloc, 可透過這個api存想放fiber內的東西 FLSSetValue, FLSGetValu, IsThreadAFiber

和thread比較 給linux porting過來用的, 差在fiber內可以schedule fiber 就是讓linux的library可以使用?? http://stackoverflow.com/questions/796217/what-is-the-difference-between-a-thread-and-a-fiber

問題: 無法看到callstack

好處: 可以當成user mode的thread schedule, 而不用使用windows 的kernel event像是setEvent, WaitForSingleObject

CoRoutine 可以讓function執行到一半中斷離開, 然後再resume 搭配fiber使用, 就不用call event了

CH13 memory 結構 memory address space 最一開始是用二進位為單位, 所以是2的次方 now: 2^32 就是4G windows給all process 4GB virtual memory in 32bit OS thread in a process can access its own address space. 4GB被分為user(process information) & kernel(windows 用的空間) space各半 所以process實際能用的是2GB(virtual),

假如今天需要大量memory, 可以在Boot.ini裡面設定user space更大,同樣會壓縮到kernel space [boot loader]

virtual address space 分四塊 (user space 64kb) null pointer assignment: help to detect null pointer, 避免pointer亂指, 會觸發accessviolation, MAX是 {} (user space) user mode: process private space, can't touch others (user space 64kb) 64 bit off limits: 防火牆避免接觸到kernel space kernelspace : windows在用的,不得reading & writing, 每個process看到的kernel space一樣

win32 user memory map (Stack) BaseAddress

(Heap)

kernel mode

user mode max address為0x7fffffff, 在x86這個bit沒用到, 有些人會亂用不會有事 但x64會出問題!!!

/LargeAddressAware : 告訴windwos compiler你有存去最上面的bit, 則系統不會對他多做事情

3 way memory management

  • memory mapped file api
  • heap memory api
  • virtualmemory api 這三個api會透過NT virtual memory mgr來存去記憶體

系統會在user space用一些東西,PEB/TEB之類的, TLS..... 可用virtual alloc來request, 可以指定特定位子的memory, 會保留 必要求follow Alloxation granularity(分配力度?) 分配力度: 要memory通常是一次拿到64kb, 不論你有沒有用完都會被保留這個大小 可以用api查系統會給你多少~ 不過PEB TEB不遵守這個規定~~

https://msdn.microsoft.com/en-us/windows/hardware/drivers/gettingstarted/virtual-address-spaces

64bit的memory長得不一樣 https://msdn.microsoft.com/en-us/windows/hardware/drivers/gettingstarted/virtual-address-spaces

results matching ""

    No results matching ""