I have been working on this little introductory project to the Producer/Consumer threading concept. For this project, I was required to share a common file resource between the two threads. One of the threads would write lines of output to the file (producer) and the other thread would read a line from the file and mark that line read with an asterisk at the end using file pointer operations(Consumer). The producer thread would then sleep for 300 milliseconds while the consumer thread would sleep for 600 milliseconds (2 writes for every 1 read essentially). This is essentially the gist of what I am supposed to do.
So far, I've written the program and gotten the output from the program that I am supposed to get. My problem though is that the lines of output in the file all appear clustered on one line like so (in this example output where I've written ten lines to file and read 9 of those lines):
when ideally I would like the file output to appear as:
Line Number# is1*
Line Number# is2*
Line Number# is3*
Line Number# is4*
Line Number# is5*
Line Number# is6*
Line Number# is7*
Line Number# is8*
Line Number# is9*
Line Number# is10
Quite frankly I don't quite understand why my initial output doesn't already show up as this. Can anyone help to shed light on this? I am finding this to be more than a little frustrating...