Category : synchronization

Background I am finishing up upgrading my MFC framework project from prototype to alpha production code. The task was to synchronize its threads. I used a mixture of mutexes, condition variables and binary semaphores. This has been mostly successful. The stackoverflow case that most resembles my question is std::condition_variable wait() and notify_one() synchronization. Problem Occasionally, ..

Read more

I have a function that copies data from one buffer to another, I need to synchronize its execution. I have such a bad option: void MainWindow::copyBuffer(VkBuffer srcBuffer, VkBuffer dstBuffer, VkDeviceSize size) { VkCommandBuffer commandBuffer; vkAllocateCommandBuffers(logicalDevice, &allocInfo, &commandBuffer); //Start recording vkBeginCommandBuffer(commandBuffer, &beginInfo); vkCmdCopyBuffer(commandBuffer, srcBuffer, dstBuffer, 1, &copyRegion); vkEndCommandBuffer(commandBuffer); //Run command buffer vkQueueSubmit(graphicsQueue, 1, &submitInfo, VK_NULL_HANDLE); //Waiting ..

Read more

I have the following piece of code #include <thread> #include <mutex> #include <algorithm> #include <vector> #include <iostream> std::vector<int> v; void f() { v.push_back(1); } void g() { v.push_back(2); } int main() { std::thread t1(f); std::thread t2(g); t1.join(); t2.join(); std::cout << v.size() << ‘n’; } If I execute this program on my system, it gives me ..

Read more

#include <iostream> #include <vector> #include <thread> #include <mutex> #include <functional> #include <any> #include <condition_variable> std::vector<std::function<void(const std::any&)>> functions; enum FunctionCodes { EXIT = -1, NOTIFY = 0, PRINT }; class Message { public: int code; std::any data; }; void perform_function(const Message& message) { return functions[message.code](message.data); } namespace X { class MessageQueue { friend class Thread; class ..

Read more