open/fopen read/fread in multithreaded environment.

S

Sheth Raxit

even thred is not part of C-std, i feel its most relavant to
comp.lang.c
hope it will not off-topic

-------
I am having data/or Text file, which is only used for reading by
multiplethreads in same process.

Reading may be done by in following possible way.
1.each Thread fopen,fread,fclose <fread may be called in loop>
2.each Thread open, read,close <fread may be called in loop>
3.Main Thread will fopen, childthread will fread in loop , mainthread
will fclose at end.
4.Main Thread will open, childthread will read in loop , mainthread
will close at end.

<in 3 and 4 above return value of open/fopen will be global value <or
may be pass to function but i think it is shared between multiple
thread.>

Assuming there will be a main thread and 60 other thread, Assuming no
thread is writing to file do i need to have any of above code having
pthread_mutex_lock/unlock ?

i.e. i want to know any code is critical section ? assuming the
variable in which they are reading are all function's local
variable,<dynamic memory are referred by differnt pointer of each
thread so no worry>

Thanks,
Raxit
"Thread, Mutex, Buggy Code, Deadline results Nightmare ...!"
 
R

Richard Heathfield

Sheth Raxit said:
even thred is not part of C-std, i feel its most relavant to
comp.lang.c

comp.unix.programmer would be more relevant than comp.lang.c - and
comp.programming.threads is another possibility, according to my news
server.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top