-2

WaitForMultipleObjects is one of several Windows kernel functions that can suspend and synchronize a calling thread with other threads until resources or etc are available, similar to flock in Linux, but handles everything but file locking.

WaitForMultipleObjects supports an array of events (can be a mixture of change notifications, console input, events, memory notifications, mutexes, processes, semaphores, threads, and timers), a timeout or polling option, and an AND/OR option and reports which fired first, and it can be used independently by multiple threads at once without knowledge of each other.

(I was looking for an IPC lock with timeout and things like using SIGALRM with flock where suggested which I can't risk using because SIGALRM might be in use in other multi-threaded libraries I don't have source to. I settled on using polling with LOCK_NB and tiny sleeps, and I am pretty sure I am not losing any "fair lock" benefits.)

8
  • 1
    From context, I am guessing you are referring to kernel calls or something similar that would be used in the context of writing a piece of software and not about something a regular user of the OS would use, is that right? Please edit your question and clarify that, bearing in mind that most of us here have no knowledge of Windows so we have no idea if this WaitForMultipleObjects is a library, a kernel call, a graphical program or what.
    – terdon
    Commented Jan 9, 2022 at 18:26
  • 2
    I don't know what WaitForMultipleObjects is specifically, but that sounds similar to select or poll. Commented Jan 9, 2022 at 18:38
  • I added a brief summary of WaitForMultipleObjects in description. Select and poll might be alternatives although I've only seen their use with sockets. I have since seen System V might have more but little used cross-process synchronization mechanisms, but I don't know anything about that. In my case, I needed to control access to shared hardware, and flock with a dummy file seemed the only choice, and adding a failsafe timeout seemed problematic. Windows has nice synchronization objects and functions that seem more appropriate than dummy files. Commented Jan 10, 2022 at 21:53
  • 3
    Maybe ask a concrete question: What are you trying to do, and what was the outcome?
    – U. Windl
    Commented Jan 11, 2022 at 7:02
  • Boost libraries for Linux might provide better synchronization objects but I suspect they are layered on top of other kernel functions not designed for those purposes. Use of select might be a possibility but it seems not designed (or named) for general synchronization. I look and find things like stackoverflow.com/questions/15651857/… System D is one effort to update Linux I am aware of; I was wondering of there are others attempting to directly support higher-level scalable kernel functions - for complex synchronization in this case. Commented Jan 12, 2022 at 1:31

1 Answer 1

0

Actually, there seems to the Futex2 work that should aim providing a low level interface that will allow to implement an equivalent to WaitForMultipleObjects in the linux kernel.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .