points by wtallis 1 day ago

A lot of that flexibility is what makes it hard to efficiently emulate (especially without kernel level support), but some of it seems too flexible to make sense as the default choice. How often does a video game really need a lock that can be shared between processes, and why should that lock type be the one that a game engine uses for almost all of its locks?

spacechild1 1 day ago

> How often does a video game really need a lock that can be shared between processes,

What do you mean? SRWLock (or the older CRITICAL_SECTION) cannot be shared between processes. A (Win32) Mutex does work across processes, but that's its entire purpose. So Windows does have different tools for different jobs.

In fact, it's really the other way round: on Linux, a futex also works across processes, but there is no equivalent in Windows. (Sadly, WaitOnAddress can only be used in a single process.)

FpUser 1 day ago

It very often being used for thread management inside single process etc. Very convenient. Nobody says it has to be default.

CyberDildonics 1 day ago

How often does a video game really need a lock that can be shared between processes,

That seems hugely useful for interprocess communication and I can immediately think of reasons to use IPC in a game. Having a separate voice process for one.

  • Dylan16807 1 day ago

    But that goes back to "how often". Not how many games use it, but how many times per second they use it. You might touch your voice process lock once per frame? That's negligible in terms of CPU time. Any half-reasonable overhead makes no difference in that lock, but might have a big impact in a more common lock.

    • CyberDildonics 1 day ago

      It absolutely can make a difference because if you have locks that are supposed to sync or wake up other processes you care about latency not cpu usage.

      • Dylan16807 1 day ago

        What specifically are you saying can make a difference?

        I'm saying that extra overhead from making your lock work across processes should be very tiny. That overhead shouldn't add much more than a microsecond in either latency or CPU usage, compared to an in-process lock.

        • CyberDildonics 1 day ago

          You were saying "reasonable overhead" makes no difference because something "isn't called much". This is not only ambiguous but also not true because latency is important.

          What calls specifically are you talking about between windows and linux? This was started by someone talking about WaitForMultipleObjects.

          • Dylan16807 1 day ago

            I wasn't excusing all overhead, I was excusing the difference in overhead caused by making the lock more flexible. Because that's what the discussion is about, a lock that can be shared between processes versus a lock that can't be. The penalty for being "too flexible".

            But assuming reasonable implementations, the difference between those two lock styles shouldn't be more than about a microsecond, should it? So that's fine for a lock that's only used 100 times a second.

            I'm not comparing windows and linux anywhere.

            • CyberDildonics 20 hours ago

              I was excusing the difference in overhead caused by making the lock more flexible

              What are the two functions you're comparing and what is the actual difference in overhead that you're talking about?

              a lock that can be shared between processes versus a lock that can't be.

              This is a dramatic black and white difference, these would be used for two different things. In that case it's apple and oranges, one would be for interprocess communication and one wouldn't.

              the difference between those two lock styles shouldn't be more than about a microsecond,

              What are you basing this on? Do you have an examples or benchmarks of the actual calls and their timings?

              fine for a lock that's only used 100 times a second.

              Again, latency isn't about how many times something is called per second. That would matter for throughput.

              • Dylan16807 17 hours ago

                > What are the two functions you're comparing

                Go ask this comment, because I'm continuing their comparison: https://news.ycombinator.com/item?id=48125795

                > In that case it's apple and oranges, one would be for interprocess communication and one wouldn't.

                The whole point of the complaint was wtallis claiming the inter-process-capable lock was being used for locks that don't need it! That's the foundation of this conversation!

                > What are you basing this on?

                Basic coding knowledge and an assumption of competency. There's no good reason for it to slow down more than that when it's used the same way. If you have a reason go ahead and tell me.

                > Again, latency isn't about how many times something is called per second. That would matter for throughput.

                I addressed both.

                The extra latency for using an overly capable lock should be negligible. That's not the problem anyone is worried about.

                • CyberDildonics 13 hours ago

                  Basic coding knowledge and an assumption of competency.

                  This is just saying "I just know", but what specific function and basic timings are you going off of? If you don't know, why are you so sure of the numbers?

                  The whole point of the complaint was wtallis claiming the inter-process-capable lock was being used for locks that don't need it! That's the foundation of this conversation!

                  They were saying it's rare to need IPC lock for video games and I don't think that's true, then I gave a scenario where you would use one.

                  • Dylan16807 10 hours ago

                    If you're not actually using it between processes, the overhead could be as small as an extra conditional. For an upper bound I think a couple wasted syscalls makes sense. Why would it be significantly slower than that?

                    But whatever, let's focus on the actual point:

                    > They were saying it's rare to need IPC lock for video games and I don't think that's true, then I gave a scenario where you would use one.

                    And I was pointing out that a voice IPC lock is still "rare" when we use the most appropriate definition of "rare" for this context. In this context of worrying that using the wrong kind of lock will slow the game down, how often we're using the lock matters. If we go 50 million CPU cycles between uses, it's "rare".

                    • CyberDildonics 9 hours ago

                      how often we're using the lock matters.

                      No, latency is what matters.

                      And I was pointing out that a voice IPC lock is still "rare" when we use the most appropriate definition of "rare"

                      This isn't really a point with explanation, it's just you saying 'nu uh', even though that was just a single example.

                      • Dylan16807 5 hours ago

                        The post you originally responded to was comparing the general idea of locks that can work between processes and ones that can't. And it was criticizing the efficiency of the former, which is a measure of throughput.

                        There's no reason for an upgraded lock to significantly change in latency. That's not what they were worried about when criticizing the idea of using the former lock as the main lock type in a game. Your most used locks need throughput.

                        So no, latency is not what matters. And I've explained why I say that in multiple ways, while you haven't given any explanation for why you're focusing on latency.

                        When they asked "how often" in the middle of that criticism, they're not looking for an example that sprinkles in a couple calls, they're looking for something that puts serious load onto the lock. Any answer that is once per frame or less is not properly addressing the question.