What does this mean serialization of threads in C ++?

I know about serializing objects and how to save them to disk, but what does serializing threads really mean? Can someone help me in this matter and point me in the right direction, please?

+8
c ++ c multithreading pthreads
source share
3 answers

You are right that these are two different values โ€‹โ€‹of serialization . You are familiar with data serialization , which involves converting a data structure into a stream of bytes in some canonical representation. With multithreading, the term serialization means mutual exclusion for a thread or process synchronization , which means that only one thread can work on the data structure at a time. C ++ 11 provides serialization between threads using std::mutex

 #include <mutex> std::mutex file_io_mutex; { std::lock_guard<std::mutex> guard(file_io_mutex); std::out << "Only one thread at a time will execute this line." << std::endl; } 

This is an example of Initialization of resources - this is Initialization (RAII) , where a resource is received and initialized at the same time and released when it goes beyond the scope (execution reaches the closing curly bracket). This is a common idiom, it guarantees that the mutex will be released even if the code throws an exception before reaching the end of the block.

+10
source share

Serialization actually means publishing in sequential form, as in one by one. Thus, serialization of flows means that a certain set of events does not occur in a sequence at the same time

Thus, a heap having serialized access to a stream means that heap calls will be executed in the order in which they are made, and will not actually occur simultaneously. This is probably done using global locking.

+7
source share

Unaware of the specific context in which you were told this, I assume that it refers to the development of a single-threaded application that simulates a multi-threaded system using a message queue.

This brings me back to the old days when I was playing the CircleMUD derivative. The whole game was implemented in one thread, but she had to deal with 50-100 players at a time. I was very amazed at how they accomplished this.

+2
source share

All Articles