I am not much into scheduling threads, i have like 4-5 threads and each of them will add data to one same buffer at random time.
How i can schedule the threads so there is no case two or more threads to access the buffer at same time ?
I am coding in C on Windows environment.
Thanks in advance.
The shared buffer needs to be protected from concurrent reads/writes by different threads. A synchronization object should be used to prevent this from occuring. Anytime a thread wants to read from or write to the shared buffer it would acquire the lock, perform its operations on the shared buffer and release the lock once it no longers requires the buffer.
An example synchronization object would be CriticalSection: