News for hackers. Stuff that matters.
Re:Threads Are a Bad Idea for Most Purposes (1995) [pdf] by dijit on Tuesday January 28, 2020 @12:42PM (#22171787)
Your comment about threading in win32 being lackluster is surprising. It was my understanding that while the OS doesn't support fork(), that it /does/ support pthreads, and that as soon as you go outside of the process itself, Windows has "better for developers" system calls. I'm speaking specifically about I/O Completion ports.

Working with epoll or select/poll is really nasty when dealing with "some data" that's coming on a socket, where as IOCP allows you to tell the kernel "as soon as you see some data destined for my thread, just populate it in the memory here, tell me when something is there and then tell me how much is there"; for high performance C++ programmers this is basically invaluable and as far as I understand there's no direct competitor in UNIX and unix-like land. (although; according to the C++ devs where I work, "kqueues are less braindead than epoll")

Re:Threads Are a Bad Idea for Most Purposes (1995) [pdf] by oppositelock on Tuesday January 28, 2020 @01:18PM (#22172334)
I never said it was lackluster, I said that it was equivalent. The differences lie around how asynchronous thread signals are delivered and handled. Win32 is less flexible in that regard, and when you're writing any kind of cross platform threaded software which includes Win32, you must make accommodations for this difference. Pthreads can't be fully emulated on Win32, so you have to have your pthread path, and your win32 path.

And yes, you correctly point out that on nix and Win32, interaction with the kernel is often different. Win32 does a lot right, I won't ever speak negatively of it, it is the desktop OS of choice by a huge margin. It's just that nix and Win32 are so different from each other, that you can't generally write a single implementation of your low level thread interaction for both classes of platforms.

Re:Threads Are a Bad Idea for Most Purposes (1995) [pdf] by dboreham on Tuesday January 28, 2020 @03:59PM (#22173957)
If you were using signals on Win32, that's the problem.
Re:Threads Are a Bad Idea for Most Purposes (1995) [pdf] by gpderetta on Tuesday January 28, 2020 @08:31PM (#22176253)
I'm not a win32 programmer, but I think that for a long time windows didn't have os provided condition variables (events are not always an adequate replacement and had nasty footguns around signaling); turns out that iti is hard to implement a cond var with posix semantics and if you managed to get a third paarty implementation it was often buggy. I think they were eventually added in Windows Vista.
Re:Threads Are a Bad Idea for Most Purposes (1995) [pdf] by PaulDavisThe1st on Tuesday January 28, 2020 @12:50PM (#22171906)
the thing that is missing (or was missing - not 100% of the current state of things right now) in nix land is the generalized concept of "waitForSomething" where "something" could include any* event/data that should/could wake a thread. kqueues help a bit, but I think it is still harder than it should be on *nix (even Linux) to write code whose semantics are "put this thread to sleep until anything happens".

If the thread is waiting on a specific set of objects (e.g. file descriptors, kqueues), then this can be done easily, but it's still not quite as simple as it has been under Windows (and by the way, IOCP is built on top of the underlying mechanism that makes this possible on Windows; they are not the mechanism itself)

Re:Threads Are a Bad Idea for Most Purposes (1995) [pdf] by theamk on Tuesday January 28, 2020 @02:55PM (#22173416)
Modern kernels support signalfd, timerfd and eventfd. With those things, it is possible to wait on almost anything.
Re:Threads Are a Bad Idea for Most Purposes (1995) [pdf] by zozbot234 on Tuesday January 28, 2020 @01:02PM (#22172113)
With io_uring this can be done on Linux as well.
Re:Threads Are a Bad Idea for Most Purposes (1995) [pdf] by StillBored on Tuesday January 28, 2020 @06:50PM (#22175510)
Not yet, read the LWN article and look at the todo list. There are a number of things still missing, and of course there are things like semaphores and generic eventing that still aren't part of io_uring.

io_uring is "different" and definitely has some advantages due to its shared ring buffer. but NT has a core/generic set of async completion/wait/etc functions that can be applied to basically the entire API surface.

Re:Threads Are a Bad Idea for Most Purposes (1995) [pdf] by gpderetta on Tuesday January 28, 2020 @08:42PM (#22176323)
I do not think you can wait on a critical section or a condition variable with WaitForMultipleEvents in windows. The same is true in linux. You can use select/poll/epoll on signalfd though.
Re:Threads Are a Bad Idea for Most Purposes (1995) [pdf] by StillBored on Tuesday January 28, 2020 @09:58PM (#22176835)
Does IORING_OP_POLL_ADD work with signalfd's (I don't really know without messing with it, how about IORING_OP_EPOLL_CTL?)?

I wouldn't assume it does until I've verified and read the code, I know last year at plumbers there was a fuss about the fact that a lot of operations which should have been working wernt. Frequently in odd ways, for example direct read worked but not direct write IIRC.

Re:Threads Are a Bad Idea for Most Purposes (1995) [pdf] by linksnapzz on Tuesday January 28, 2020 @04:20PM (#22174162)
My understanding is that as of Solaris 10 && AIX ...6.1? there are IOCP implementations available for use, although they might not be enabled in the OS at install.
Re:Threads Are a Bad Idea for Most Purposes (1995) [pdf] by trentnelson on Tuesday January 28, 2020 @04:16PM (#22174112)
You might find this deck interesting: https://speakerdeck.com/trent/pyparallel-how-we-removed-the-...

There is no equivalent in UNIX land to the thread-agnostic asynchronous I/O primitives available on NT. When paired with a robust threadpool API (Vista+), it is an unbeatable platform.