Slashdot Mirror


Information for Managers - Understanding pthreads?

dnotj asks: "The boss (who is very technically astute) says: NO to using pthreads in any of our production applications. He wants us to do things the old fashion way (fork(), exec(), shared memory, etc). His reason for this is that he doesn't understand pthreads (by his own admission). Hence, he is limiting us to using methods and techniques that he understands. He is reasonable and would see our side (the developers) if presented with enough understanding in a satisfactory format. What I'm looking for are document technically detailed yet directed more towards management. Not something on the level of 'pthreads for Dummies', but more along the lines of 'pthreads for Managers'. Any suggestions? URLs or Books are fine."

5 of 69 comments (clear)

  1. Think this through.... by cybermace5 · · Score: 5, Insightful

    Managers aren't always wrong.

    Laugh, but it seems to be a common attitude that a manager is never right, and never will be.

    Your manager is not there to code, he's there to keep all of you developers on task. Apparently, for some reason he needs to understand your code, in order to do his job to his satisfaction.

    Actually, he may not NEED to understand pthreads at all. But I believe his approach is pretty smart in this case. Why should he allow you to adopt a new method, when you cannot explain it to him?

    I wouldn't let you use pthreads either, if my paycheck depended on you getting your job done.

    --
    ...
  2. Re:But separate processes ARE better. by Blob+Pet · · Score: 4, Informative

    a pretty good summary that i agree with
    taken from http://basil.cs.uwp.edu/Cs370/notes/Threads.doc:

    Advantages (Thread vs. Process):
    -Much quicker to create a thread than a process.
    -Much quicker to switch between threads than to switch between processes.
    -Threads share data easily

    Disadvantages (Thread vs. Process):
    -No security between threads:
    ---One thread can stomp on another thread's data.
    -For threads which are supported by user thread package instead of the kernel:
    ---If one thread blocks, all threads in task block.

    --
    "...today consumers have been conditioned to think of beer when they see a bullfrog..."
  3. technically astute? by aminorex · · Score: 4, Insightful
    Threads are a fork that keeps all memory shared
    except the stack. That's pretty darn simple, and
    probably all he needs to know.


    However, he's probably right. Threads are horribly
    abused in most applications. They create bloat
    and spaghetti code opportunities that lead to
    user dissatisfaction and unreasonable maintenance
    costs.


    Threads should be used if you need SMP scaling
    for a I/O intensive application, or shared memory
    decomposition of a problem space dominates the
    structure of the code. Otherwise, small
    is beautiful, and asynchronous I/O is far more
    efficient and elegant (which means maintainable).

    --
    -I like my women like I like my tea: green-
  4. some disadvantages... by Polo · · Score: 4, Informative

    You know, there are a lot of practical disadvantages to threads.

    Threads can be a lot harder to debug.
    I don't think gdb really understands threads very well. Other application support is spotty as well. Actually, Solaris has pretty good thread-aware debugging and has good threading tools like deadlock tools.

    People who write threaded applications also seem to think it makes life easier. They say - I'll just have a read thread and a write thread and a processing thread. ...except that the read thread is usually written with blocking reads and it's hard to recover when you want to kick that thread out of the read to terminate or restart cleanly.
    So people end up using select() anyway. And then they still need interprocess communication to kick the read thread out of the select sometimes.

    I think you have to be a better programmer to use threads - you have to be aware of the normal issues plus all the threading issues. Avoid cancelling threads. You have to be very clear how you do signal handling. You have to lock all your data. Don't use fork+exec AND threads. You have to keep track of multiple threads, especially during error conditions.

    And you have to be a much better debugger to debug someone else's threaded application.

    Not that there aren't good applications for threads, just be aware of the complications.

  5. Threads are *way* overrated by Panoramix · · Score: 4, Insightful

    Just a short rant on my experience and conclusions regarding threads. Me, having been formed in the "new age" school of programming (trained on the Commodore Amiga), always used threads. Used to design all my software with threads in mind. But not anymore. Since my jump to Unix, some five years ago, I've experienced a rather deep change of perception on this issue.

    IMO, threaded code is much, much harder to implement correctly, and to debug, than single-threaded code. I used to blame the crappy thread support of many Unix libraries and tools. But now that gdb supports threads, along with pretty much everything else (except gprof, but the workaround is simple), I've found that it still is a PIA to debug all but the simplest threaded apps.

    After years of hard work trying to determine what library calls are not reentrant, how are asynchronous signals delivered in each platform you support (God! Never, ever, ever mix threads and signals when writing portable code, not if you can avoid it), and which objects should be synchronized to get the best compromise between sync overhead and avoiding trashing the heap, you just fall in love with a design in which no locking is necessary at all. No ambiguities in library calls, no undocumented whatever_r() calls, no weird signal handling. A design in which a single core dump can tell you EXACTLY what was your program doing and why did it crash. Really, the simplicity and elegance of Unix programming without threads is just beautiful. The best adjective I can come up with is "liberating".

    Of course, you do have to switch to a state-machine kind of mentality when designing your applications. It is not easy (was not easy for me, at least). But it can be done very cleanly and elegantly (for an example, look for the "State" pattern, the one in which you derive classes for representing your state machine states). If portability is not an issue, it can also be done very efficiently, if you use IO signals instead of select().

    Now, having said all that, I'll now point out that I still use threads, because my code usually has to run on WIN32 too, and programming without threads there is hell (not that programming with them is much better). But I avoid threads as much as I can. I still worry about writing reentrant functions, because I find that to be a very good practice, even if no threads ae involved. But threads are used only when no other portable solution cuts it (like when checking asynchronusly for activity on non-socket descriptors, on WIN32).