Results 1 to 3 of 3

Thread: QFile and thread-safety

  1. #1
    Join Date
    Aug 2006
    Posts
    44
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QFile and thread-safety

    I know (almost) all methods in QFile are reentrant, but what about thread-safety?

    - Can two threads access the hard disk at the same time, so in other words, is disk access serialized internally?
    - Can two threads access the same file at the same time? I suppose this is not an issue if the first point is not an issue, since serialized hard disk access would mean there are no potential conflicts here.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QFile and thread-safety

    Quote Originally Posted by Raistlin View Post
    - Can two threads access the hard disk at the same time, so in other words, is disk access serialized internally?
    - Can two threads access the same file at the same time? I suppose this is not an issue if the first point is not an issue, since serialized hard disk access would mean there are no potential conflicts here.
    This all depends on the operating system. QFile simply forwards its tasks to native file API.

    As a general rule you shouldn't write to the same file from more than one context at once (be it threads or processes), because the order of calls can differ and filling the file buffer might even cause different datagrams to be mixed together.

  3. #3
    Join Date
    Aug 2006
    Posts
    44
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFile and thread-safety

    Luckily, I can only read the same file from different threads, each thread writes different files to disk. So I guess in this context I can not expect any real difficulties.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.