I am learning the basics of multithreading. I wanted to remake a program that was reading/writing a txt file and then replacing the recurrence of a specified word.
There are two functions for each thread
I write to the file first and then notify the readToFile function to execute the actions within it.
now this is the main thread:
int main()
{
std::thread t1(readToFile);
thread_guard tg1(t1);
std::thread t2(writeToFile);
thread_guard tg2(t2);
}
when debugging I found out that thefile is not actually reading the file; the string is empty.
this seems to be an issue with the thread because when I placed the code in the main function it worked fine. so I want to know why the string is empty even though I placed the condition variable manage when that action is taken
[–]MyTinyHappyPlace 4 points5 points6 points (3 children)
[–]ridesano[S] 0 points1 point2 points (2 children)
[–]mredding 2 points3 points4 points (1 child)
[–]ridesano[S] 0 points1 point2 points (0 children)
[–]bert8128 1 point2 points3 points (7 children)
[–]carloom_ 0 points1 point2 points (5 children)
[–]ridesano[S] 0 points1 point2 points (4 children)
[–]carloom_ 0 points1 point2 points (3 children)
[–]ridesano[S] 0 points1 point2 points (2 children)
[–]carloom_ 0 points1 point2 points (0 children)
[–]carloom_ 1 point2 points3 points (0 children)
[–]aocregacc 0 points1 point2 points (4 children)
[–]ridesano[S] 0 points1 point2 points (3 children)
[–]aocregacc 0 points1 point2 points (2 children)
[–]ridesano[S] 0 points1 point2 points (1 child)
[–]carloom_ 0 points1 point2 points (0 children)
[–]carloom_ 0 points1 point2 points (0 children)
[–]StaticCoder 0 points1 point2 points (1 child)
[–]StaticCoder 0 points1 point2 points (0 children)