July 9th, 2011, 07:59 AM
Continous Serialization and Reading at the same time.
I have a list of objects that is periodically being added too (~500 times per second). I am trying to serialize this list periodically without rewriting the entire list. I would then like to open it on a networked computer while the serializing computer is still writing to the file. Is this possible?
Thanks in advance.
July 10th, 2011, 08:38 AM
Re: Continous Serialization and Reading at the same time.
Originally Posted by carle257
Consider this problem to be a multithreading problem. What you have here is a shared resource (i.e the file) being accessed by two threads (one thread from each process).
The rules of thread safety tell you that you must synchronize access to the shared resource when at least one thread is writing to the data (and the other thread is reading or writing).
Without any form of synchronization, you have a very good chance that the file will become corrupted (i.e you will have incomplete, invalid xml statements).
In fact, since you are writing to the file about 500 times/sec, you have an extremely high chance of corruption.
Even if you only wrote to the file once every second, without synchronization, you have the possibility of data corruption, which most systems find unacceptable.
Bottom line is you need to synchronize access to the file when one thread is writing and the other thread is reading.
Tags for this Thread
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!