Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Question Does linux execute threads of a process in parallel?

    I'm beginning to wonder if Linux actually runs threads of a process in parallel without affecting the other thread? Why, because I took an app that added threads in Windows and got a 40% increase in speed and adding Linux threading there was 0% increase. Basically a ResetEvent, CreateEvent, and WaitForSingleObject function was created and conditional preprocessor defines used so the same core code executed under Window also executes under Linux. Now, how this works is there are three threads, one for the GUI update (idle for the most part but wakes up every 1 second to update GUI), the next is the main processing thread that does a fair amount of CPU intensive operations on data, the final one is one that simply reads data from the hard drive. So while thread 2 is busy, thread 3 goes and reads the next data to a buffer, and then when ready, thread 2 checks if the data is ready or it has to wait (pthread conditions), checking this I find that 95% of the time the data has already been read and ready for use (memcpy instead of needing to read from hard drive), however, the processing time is always the same, this is reading in about 18G of data. Doesn't make any since. I saw via htop that the two threads could sometimes use the same CPU as Linux moved them around, however, I later set the affinity of each thread to run on their own CPU (dual core) and see in htop that it sticks, but same result, no improvement, So I'm starting to wonder if Linux isn't running things in parallel, but instead only running one thread in a process per some time period?? Kernel is SMP i686. Anyone have any ideas?

  2. #2
    well I timed the code with both sections, if using threading it was around 151 seconds and just reading 152 seconds, so perhaps linux was doing read-ahead on the data being read so it was already cached.

  3. #3
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Linux definitely parallels threads assuming there are cores to do so. However, since Linux deals with I/O much more efficiently than Windows (generally), you may not see as much of a speed up, depending upon your application. Try it with CPU-intensive operations and you will probably see a (almost) 2x speedup in performance of 2 vs. 1 threads. I/O is still gated on the I/O sub-system in many cases, though Linux does aggressive I/O caching, much more so than Windows.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  4. $spacer_open

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts