This is my last assignment for the semester and I'm having a bit of a problem going about it. I know what I want to do, just not 100% sure how to implement it. There's a lot more involved then what I'll mention, but that stuff I know I can do.
My basic problem is that I have a single reader thread and single writer thread. The reader thread constantly grabs data from a text file and dumps it into a buffer of some arbitrary size. The writer thread will constantly be taking the data from the buffer and writing lines of it out to a separate text file.
The only major conditions that has to be considered is that if the buffer is maxed out, the reader thread has to cease operating until some of the existing data has been moved out of the buffer. Also, if the buffer is empty, the writer thread has to halt until data is in the buffer again.
I want to implement a semaphore to tell the respective thread to either wait or continue based on the condition of the buffer. I just don't know how to go about checking the current size of the buffer to know what to do.
If you need any more information just let me know and I'll try to give an answer as best I can. It would be preferable if I could do this in C++ but I can also use Java if it turns out to be easier (which it is in some cases for these sort of things).
Thanks in advance for any help.
My basic problem is that I have a single reader thread and single writer thread. The reader thread constantly grabs data from a text file and dumps it into a buffer of some arbitrary size. The writer thread will constantly be taking the data from the buffer and writing lines of it out to a separate text file.
The only major conditions that has to be considered is that if the buffer is maxed out, the reader thread has to cease operating until some of the existing data has been moved out of the buffer. Also, if the buffer is empty, the writer thread has to halt until data is in the buffer again.
I want to implement a semaphore to tell the respective thread to either wait or continue based on the condition of the buffer. I just don't know how to go about checking the current size of the buffer to know what to do.
If you need any more information just let me know and I'll try to give an answer as best I can. It would be preferable if I could do this in C++ but I can also use Java if it turns out to be easier (which it is in some cases for these sort of things).
Thanks in advance for any help.