|
Threads and fstream
Can someone (read: Valmont,lol) explain to me how to share an open fstream between 2 threads in a multithreaded program? I tried declaring it as a global outfile, but when it gets to the function in another file it says it doesn't recognize the variable outfile. My teacher said something about declaring it a pointer to a fstream then dereferencing it in the function, but I haven't had any luck doing that yet.
The program is fundementally simple, output greeting message, start thread, get 2 random nums, wait for child, output both nums and child threads id. The thread runs function void* getnumbers (void* data), which generates random nums, outputs this threads id and numbers to file, then returns numbers.
I hope you can explain this to me.
|