Multithreading
-
I am creating an application that is multithreaded and all the threads are accessing the same shared memory. The data coming into the memory should be processed in sequential order. Like if 1,2,3,4,5 comes in the memory then it should be processed in same order. I have used critical section around my memory, but I still get into a race condition where data is not grabbed by the thread in sequential order. Am I missing anything else to prevent threads from race condition? Thanks. ACpp
-
I am creating an application that is multithreaded and all the threads are accessing the same shared memory. The data coming into the memory should be processed in sequential order. Like if 1,2,3,4,5 comes in the memory then it should be processed in same order. I have used critical section around my memory, but I still get into a race condition where data is not grabbed by the thread in sequential order. Am I missing anything else to prevent threads from race condition? Thanks. ACpp
if you want to manage the order of working threads you have to use something to tell them, if it's their turn to work. critical sections are for keeping common data thread safe. Only one thread can enter critical section at given time. but there are no rules which thread can do it in cs case. It depends on system and threads state. If you want to set order you can use WaitForSingleObject or WaitForMultipleObjects with SetEvent method to let threads work when it's their time.
-
I am creating an application that is multithreaded and all the threads are accessing the same shared memory. The data coming into the memory should be processed in sequential order. Like if 1,2,3,4,5 comes in the memory then it should be processed in same order. I have used critical section around my memory, but I still get into a race condition where data is not grabbed by the thread in sequential order. Am I missing anything else to prevent threads from race condition? Thanks. ACpp
Yes, you are. Google 'multi thread patterns'. It is a long path, but when you arrive, you're likely to feel it was worth it.
Pablo. "Accident: An inevitable occurrence due to the action of immutable natural laws." (Ambrose Bierce, circa 1899).