open/fopen read/fread in multithreaded environment.

Discussion in 'C Programming' started by Sheth Raxit, Nov 23, 2007.

  1. Sheth Raxit

    Sheth Raxit Guest

    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 ...!"
    Sheth Raxit, Nov 23, 2007
    #1
    1. Advertising

  2. 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.

    --
    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
    Richard Heathfield, Nov 23, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joerg Gippert
    Replies:
    9
    Views:
    666
    John C. Bollinger
    Oct 10, 2003
  2. Nonee
    Replies:
    2
    Views:
    2,633
    Neredbojias
    Oct 25, 2005
  3. John

    is fopen/fseek/fread buffered?

    John, Oct 1, 2005, in forum: C Programming
    Replies:
    2
    Views:
    626
    SM Ryan
    Oct 1, 2005
  4. Michel Rouzic
    Replies:
    4
    Views:
    1,820
    Michel Rouzic
    Apr 28, 2008
  5. Replies:
    18
    Views:
    392
    Thomas 'PointedEars' Lahn
    Dec 19, 2008
Loading...

Share This Page