Find the answer to your Linux question:
Results 1 to 2 of 2
hi...... i'm working on thread programming... my question is : when the multi threaded program does not give us better performance than single threaded program???...
  1. #1
    Just Joined!
    Join Date
    Oct 2007
    Posts
    10

    Question threads!!

    hi......
    i'm working on thread programming...

    my question is : when the multi threaded program does not give us better performance than single threaded program???
    Last edited by techieMoe; 11-06-2007 at 05:09 PM. Reason: Please do not post in all bold text.

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Quoth sunlife:
    when the multi threaded program does not give us better performance than single threaded program?
    By "better performance" I assume you mean "lower runtime".

    The best rules I have come across for optimizing your programs are these:
    1. If you are not an expert programmer, do not optimize.
    2. If you are an expert programmer, do not optimize yet.

    There is more wisdom in these rules than meets the eye.

    If you want to optimize your program, it's best to figure out where your program is spending most of its time. Optimizing everything in sight usually makes for a needlessly complex program, expensive to maintain.

    If you write a program using POSIX threads and then figure out where your program spends most of its computing resources, it's extremely unlikely that the POSIX threads implementation will consume much compute time.

    In fact, if your threads don't communicate with each other very tightly, it's usually even better to do this instead of using POSIX threads:
    1. Use fork() to make separate processes.
    2. Before fork()ing, use mmap() on /dev/zero to allocate memory to be shared between all processes.
    3. Use file locking for synchronization between your processes.

    Why do that instead of POSIX threads? Do it because you'll have a separate heap space for each process. This is more important than it looks. With POSIX threads sharing a single heap space, one thread can die because another thread has stomped on something in the heap, and it can be tricky to try to reproduce those conditions reliably.

    Better yet (if your program is simple enough), and probably the fastest-running also:

    Design your program around an event loop which reacts to any I/O. Open all files, devices, network interfaces, and flying pigs asynchronously. Use select() to figure out what to do each time through the loop.

    Hope this helps.

Posting Permissions

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