View Full Version: Threads and File access

C++ Learning Community > C++ Help > Threads and File access


Title: Threads and File access


kasun04 - February 7, 2007 02:05 PM (GMT)
I got one class which extends from a Thread class.
In the main process I'm accessing (read and write) a file named "stt.txt" also in the thread (in thread function) I'm accessing the same file (reading n writing).

1. Will this cause an error.
2. And how to perform such a task in C++.
OS: Solaris 10
compiler : gcc 3.4.3
Thread Lib :POSIX Threads <pthread.h>

myork - February 7, 2007 02:24 PM (GMT)
QUOTE (kasun04 @ Feb 7 2007, 09:05 AM)
I got one class which extends from a Thread class.
In the main process I'm accessing (read and write) a file named "stt.txt" also in the thread (in thread function) I'm accessing the same file (reading n writing).

1. Will this cause an error.
2. And how to perform such a task in C++.
OS: Solaris 10
compiler : gcc 3.4.3
Thread Lib :POSIX Threads <pthread.h>


As long as you use the same file handel in both threads everything should be OK.


Of course if both threads write at the same time you do not know what order items will be placed in the file.




Hosted for free by InvisionFree