Thread: Threads and Files

  1. #1
    Registered User
    Join Date
    Sep 2013
    Location
    Jamaica
    Posts
    134

    Threads and Files

    Well, I've basically completed my project but I have one last question. I'm wondering if threads reading from the same file is affected by each other.

    IF thread 1 rewinds a file with thread 2 be affected by this file rewind?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Unless you see on the API a nice little comment like "this is thread safe", you generally assume that everything else is NOT thread safe.

    File handles are typically owned by a process, not a thread.
    So you should generally expect surprises when you go sharing file handles between threads.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    I don't know what you're trying to do but couldn't you remove the possible problem by giving each thread its own file handle?

  4. #4
    Registered User
    Join Date
    Sep 2013
    Location
    Jamaica
    Posts
    134
    Well yea each thread create its own file handler, do they don't affect each other during runtime. I just thought it would because you cant allocate memory in the threads it will cause a SEGSIGV so I thought it would do the same with files but it doesnt

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 22
    Last Post: 12-14-2012, 11:00 AM
  2. Threads, Files and a Test
    By nvoigt in forum Windows Programming
    Replies: 2
    Last Post: 11-14-2005, 09:27 AM
  3. Threads, synchronisation and temporary files
    By Magos in forum Windows Programming
    Replies: 3
    Last Post: 03-03-2005, 05:01 PM
  4. using threads to write & read from files
    By kishorepalle in forum C Programming
    Replies: 4
    Last Post: 10-19-2004, 05:19 PM
  5. a point of threads to create multiple threads
    By v3dant in forum C Programming
    Replies: 3
    Last Post: 10-06-2004, 09:48 AM