470,859 Members | 1,628 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,859 developers. It's quick & easy.

open/fopen read/fread in multithreaded environment.

even thred is not part of C-std, i feel its most relavant to
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

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>

"Thread, Mutex, Buggy Code, Deadline results Nightmare ...!"
Nov 23 '07 #1
1 5505
Sheth Raxit said:
even thred is not part of C-std, i feel its most relavant to
comp.unix.programmer would be more relevant than comp.lang.c - and
comp.programming.threads is another possibility, according to my news

Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 23 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Cam | last post: by
6 posts views Thread by DigitalDragon | last post: by
1 post views Thread by Michael Ferrier | last post: by
11 posts views Thread by typingcat | last post: by
6 posts views Thread by Rolf Schroedter | last post: by
8 posts views Thread by Asma | last post: by
13 posts views Thread by Blue | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.