News for hackers. Stuff that matters.
Re:C++11 lock-free command buffers for multi-thread rendering by dragontamer on Monday June 17, 2019 @07:08PM (#20208201)
Okay, now that I've had some time to look at other things and come back to this, lemme offer some more detailed questions.

COMMAND_QUAL::addCommand uses fetch_add(1, std::memory_order_relaxed); It seems like this is sufficient for memory-consistency for the list, but I'm worried about the eventual sort() command.

In particular, your update in "addCommand" is as follows:

    const uint32_t currentIndex = m_currentIndex.fetch_add(1, boost::memory_order_relaxed);
    // asserts removed
    CommandPair& pair = m_commands[currentIndex];
    pair.cmd = packet;
    pair.key = key;
How does COMMAND_QUAL::sort() know that the other threads are "done adding" and that pair.key is a valid value for comparison? My race-condition would be "sort" has been called, while some thread is still setting pair.key=key, which may corrupt the command/key packet.

-----------

EDIT: Oh, you answered this in your blogpost. Lol. You assume that the user waits and safely calls sort after waiting.

Okay, that's perfectly acceptable in my eyes. I'll leave this post up for discussion purposes, even if I answered my own question.

Re:C++11 lock-free command buffers for multi-thread rendering by tuxalin on Monday June 17, 2019 @08:15PM (#20208626)
Correct, you could also use a double buffering approach to avoid that, if possible, depending on your use case. Feel free to reach out if you have any other questions.