Results 1 to 2 of 2

Thread: Threads and I/O

  1. #1
    Join Date
    Oct 2009
    Beans
    90

    Threads and I/O

    Hello,

    when I learned about threads either I thought (or I read, I can't remember which) that they would be good to handle I/O. I mean, if I have to write stuff in 3 files and I want to keep processing, I can make 4 threads, 1 will be doing the processing work, and the other 3 will be dedicated to write in one file each. In this way I can keep computing all the time while the "writer threads" wait for I/O operations to carry out.
    Recently though, someone told me that he wrote a program that had a lot of I/O operations, and for such reason threads were so bad he actually had to disable them.

    I am curious, who is wrong?

    Mind that his program uses MPI, so I guess he can use some processes to do the I/O while others carry out computations. So maybe, if the answer to the previous question is "depends", a better question could be:

    Is it really better, performance wise (time and memory), to handle I/O via processes and MPI instead of threads?
    Last edited by Dirich; June 25th, 2013 at 11:53 AM.

  2. #2
    Join Date
    Jun 2010
    Location
    Loznica Serbia
    Beans
    126
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Threads and I/O

    Threads are bad when they all read or write to the same source. If all four threads were writing to the same file the written text would get mixed up and you would get a lot of gibberish in that file. But that happens only when multiple threads use the same file, I don't see any problem with your design, all threads have separate outputs so it should work fine.
    Performance-wise, there shouldn't be any problems, MPI might add some overhead but it won't be too big.
    About the processes vs. threads, some languages (most notably Python and Ruby) have a Global Interpreter Lock (GIL) that prevents threaded programs from reaching maximum performance on a multi core processors.If your language has GIL and you need the performance of multiple cores, you should consider multiprocessing. If you don't have to worry about GIL then use threads, they are much more lightweight and have less overhead than processes.
    Windows is not user friendly,it's just user familiar

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
  •