Threads and Files

This is a discussion on Threads and Files within the C Programming forums, part of the General Programming Boards category; Well, I've basically completed my project but I have one last question. I'm wondering if threads reading from the same ...

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

    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,540
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    1,098
    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
    126
    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, 10:00 AM
  2. Threads, Files and a Test
    By nvoigt in forum Windows Programming
    Replies: 2
    Last Post: 11-14-2005, 08:27 AM
  3. Threads, synchronisation and temporary files
    By Magos in forum Windows Programming
    Replies: 3
    Last Post: 03-03-2005, 04: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21