Does anyone have experience debugging/profiling highly contended critical sections of STM vs a more traditional mutex implementation? At the end of the day something has to mediate concurrent access to shared memory, there’s no free lunches, and mutexes are so well optimized, profiled, and understood. I’m unclear if the same applies to STM where a transaction may need to be retried an unbounded(?!) number of times.
Peredvizhnikov Engine: Lock-free game engine written in C++20
161–170 of 183 posts
Re: Peredvizhnikov Engine: Lock-free game engine written in C++20
#162Earlier quoted context omitted.
Aren't lock free data structures more about reducing the impact of contention than throughput under low contention?
Lock free is kind of an overloaded term that can mean a variety of things depending on what the user is thinking. Usually the goal is being able to make forward progress even if one thread is context switched out by the OS scheduler, which might be called wait-free or non-blocking. Using mutexes (unless you can prevent OS scheduling, interrupts, etc) makes this property impossible to achieve. In general, MPSC queues…
There's one significant advantage that a locked vector or deque has over MPSC/MPMC queues: the consumers can dequeue all messages in a single operation by locking the vector, swapping it with an empty vector (typically, that's just 3 words), and locking it again. That's such a simple operation that it will typically be as fast or even faster than a single pop-one-message operation in an MPSC/MPMP. Similarly, if the vector is empty, a producer can push any number of messages in a single, constant-time operation.
Re: Peredvizhnikov Engine: Lock-free game engine written in C++20
#163Re: Peredvizhnikov Engine: Lock-free game engine written in C++20
#164I have an Actor framework which uses a vanilla std::deque for method pointers, and to add messages to the queue, the locking technique is a Benaphore (the original Futex, which uses an atomic and a locking primitive, with the twist that my locking primitive is a combo of spinlock/mutex based on retry count). Nothing special. Benchmarks show that very rarely does the message push function block, and the chance of an O…
Re: Peredvizhnikov Engine: Lock-free game engine written in C++20
#165.. because doing lock-free programming is least of problems when creating games.
Re: Peredvizhnikov Engine: Lock-free game engine written in C++20
#166Earlier quoted context omitted.
This is usually called "soft realtime" -- you want it to be fast but it's not wrong if it misses deadlines. It doesn't violate correctness of the system to miss a deadline. In a "hard realtime" system, it is a fatal error if the system misses a deadline because correctness is violated. I presume this difference is what OP is talking about. Games are never hard realtime; missing frame deadlines reduces user experience…
> Games are never hard realtime; missing frame deadlines reduces user experience but it doesn't break the game. It depends on whether the game is multi-player and, if so, how it keeps the different players in sync with each other. Games that rely on deterministic gameplay can desync (two players don't see the same world state) and abort if one player's simulation drops a frame while the other doesn't.
Network latency is a thing and your state management subsystem absolutely has to be fault tolerant.
Re: Peredvizhnikov Engine: Lock-free game engine written in C++20
#167Earlier quoted context omitted.
This is usually called "soft realtime" -- you want it to be fast but it's not wrong if it misses deadlines. It doesn't violate correctness of the system to miss a deadline. In a "hard realtime" system, it is a fatal error if the system misses a deadline because correctness is violated. I presume this difference is what OP is talking about. Games are never hard realtime; missing frame deadlines reduces user experience…
> Games are never hard realtime; missing frame deadlines reduces user experience but it doesn't break the game. It depends on whether the game is multi-player and, if so, how it keeps the different players in sync with each other. Games that rely on deterministic gameplay can desync (two players don't see the same world state) and abort if one player's simulation drops a frame while the other doesn't.
Deterministic gameplay means after the same x frames with the same external inputs you will end up with the same state y on different hardware. Therefore we only need to make sure the clients stay within a reasonable margin. We can do this by waiting for all players inputs so moving at the slowest speed possible which is the lock-step method. Or we can change our measured frame time so each tick (which still ticks the same amount of sim time) is seen as faster or slower. That way we can track the other frames that other clients have completed from the input they send and slow or speed ourselves up to maintain a decent margin. This is the scheme used in rollback networking as the naïve implementation where this isn’t the case forces all rollbacks onto the faster machine.
Re: Peredvizhnikov Engine: Lock-free game engine written in C++20
#168Earlier quoted context omitted.
I am sure I have memories of how hard it was to support a range of hardware when I had to write specifically for each piece. When I had to write separately for a Soundblaster card and an Adlib and a Disney SoundSource and a Roland and a Gravis. And that was just the sound cards. Writing for different hardware became so much easier when OpenGl and DirectX came into being. Suddenly I just had to write to these APIs. I…
Yeah, and Tandy graphics were different from EGA or VGA, just enough that you needed to write different display code for them. And you had to get the user to tell you which ports/IRQ numbers half of their hardware was configured at. We have way better hardware abstractions in the OS today, which I would agree makes modern development easier overall.
Different world. So much easier now.
Re: Peredvizhnikov Engine: Lock-free game engine written in C++20
#169Earlier quoted context omitted.
Say you are in the middle of building a house. The foundation has been built and they are framing it up. Is it a house?
No, because otherwise you wouldn't say "the foundation has been built". You'd say the "the house has been built". Does a house need a foundation? Yes. Is the foundation the same as the house? No.
Re: Peredvizhnikov Engine: Lock-free game engine written in C++20
#170Earlier quoted context omitted.
Say you are in the middle of building a house. The foundation has been built and they are framing it up. Is it a house?
No, and if you accept it as a house then this is a recipe for developing a bad habit of leaving a trail of half finished projects in your wake.