Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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 [2] https://github.com/WebKit/WebKit/blob/main/Source/bmalloc/li...



At 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.


These VirtualAlloc's may intermittently fail if the pagefile is growing...


Ah yeah, I see Firefox ran into that and added retries:

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.


This 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.


Never knew about the destructor feature for fiber local allocations!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: