5 ms·
I recently ported WebKit's libpas memory allocator[1] to Windows, which used pthreads on the Linux and Darwin ports. Depending on what pthreads features you're
by igrunert 1y ago
I recently ported WebKit's libpas memory allocator[1] to Windows, which used pthreads on the Linux and Darwin ports. Depending on what pthreads features you're using it's not that much code to shim to Windows APIs. It's around ~200 LOC[2] for WebKit's usage, which a lot smaller than pthread-win32.
[1] https://github.com/WebKit/WebKit/pull/41945 https://github.com/WebKit/WebKit/pull/41945
[2] https://github.com/WebKit/WebKit/blob/main/Source/bmalloc/libpas/src/libpas/pas_thread.c https://github.com/WebKit/WebKit/blob/main/Source/bmalloc/li...
- adzm 1y agoNever knew about the destructor feature for fiber local allocations!
- malkia 1y agoThese VirtualAlloc's may intermittently fail if the pagefile is growing...
- igrunert 1y agoAh yeah, I see Firefox ran into that and added retries: https://hacks.mozilla.org/2022/11/improving-firefox-stability-with-this-one-weird-trick/ https://hacks.mozilla.org/2022/11/improving-firefox-stabilit... Seems like a worthwhile change, though I'm not sure when I'll get around to it.
- account42 1y agoThis is something you also need to do for other Win32 APIs, e.g. file write access may be temporarily blocked by anti-virus programs or whatever and not handling that makes unhappy users.
- kjksf 1y agoAt the time (11 years ago) I wanted this to run on Windows XP. The APIs you use there (e.g. SleepConditionVariableSRW()) were only added in Vista. I assume a big chunk of pthread emulation code at that time was implementing things like that.