Threads and global variables
Hello!
I hope this question isn't too stupid. :) I don't have a real clue about threads yet. My question is:
I have several threads for my small chatserver, each thread is using one global string var and another thread is constantly pushing data into those buffers. Right now I have it that the main thread waits for the buffer to be empty before writing new stuff to it but that is too slow in the long run (because the chatthreads only send their buffer every second). So I want to attach the new info to the buffer if possible. Will this cause problems (errors?) when one thread is trying to delete this buffer (or parts of it) while another is trying to write into it at the same time? Or can't this happen?
I'm still thinking of the times when I worked with ASCII databases. Whenever I had several processes writing and reading from it at once, chances are that the whole DB would be deleted. =)
I hope this wasn't too confusing.