Hacker News new | past | comments | ask | show | jobs | submit login

Isn't threading generally handled by POSIX as well? The p in pthreads?

If you're writing C code in 2024 and your target is a system that has an OS, then it's safe to use select and poll. They're going to be there. This hand wringing over "oh no, they aren't supported on every platform" is silly because the only platforms where they don't exist are the ones where they don't make sense anyway.




> Isn't threading generally handled by POSIX as well?

C11 added threading to the stdlib (https://en.cppreference.com/w/c/thread).

MSVC is really late to the party (as always): https://devblogs.microsoft.com/cppblog/c11-threads-in-visual...

AFAIK select() and poll() are still not supported in MSVC though. IIRC at least select() is provided by 'WinSock' (the Berkeley socket API emulation on Windows), but it only works for socket handles, not for C stdlib file descriptors.

In general, if you're used to POSIX, Windows and MSVC is a world of pain. Sometimes a function under the same name exists but works differently, and sometimes a function exists with an underscore, and still works differently. It's usually better to write your own higher level wrapper functions which call into POSIX functions on UNIX-like operating systems, and into Win32 functions on Windows (e.g. ignoring the C stdlib for those feature areas).


> MSVC is really late to the party (as always)

Mostly because before Satya took over, C on Windows was considered a done deal, and everything was to be done in C++, with C related updated only to the extent required by ISO C++ compliance.

https://herbsutter.com/2012/05/03/reader-qa-what-about-vc-an...

Eventually the change of direction in Microsoft's management, made them backtrack on that decision.

Additionally, in what concerns C++ compliance, they are leading up to C++23 in compliance, while everyone else is still missing on full modules, some concepts stuff, parallel STL,...

Although something has happened, as the VC++ team has switched away to something else, maybe due to the Rust adoption, .NET finally being AOT proper with lowlevel stuff in C#, or something else.

https://old.reddit.com/r/cpp/comments/1ea6gho/microsoft_when...


I guess the difference is that you need maybe 5 peeps to keep the C compiler frontend and stdlib uptodate (in their spare time), but 500 fulltime to do the same thing for C++, and half of those are needed just to decipher the C++ standard text ;)


That isn't something I can disagree with, now if only WG14 took security more seriously.


> If you're writing C code in 2024 and your target is a system that has an OS, then it's safe to use select and poll.

Not on Windows. My target systems include Windows. The world is much larger than just Linux/POSIX.


I mean, no. The most basic of uses on windows require #ifdef'ing as the prototypes, types, error codes and macros in wsock2 aren't exactly the POSIX ones (WSAPoll instead of poll, etc.).

Also some software still target windows xp and this one doesn't even have poll, only select




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

Search: