What are threads for in UNIX?

Posted on 2006-05-09
Last Modified: 2010-04-21
I know that 'Threads' defines interfaces and functionality to support multiple flows of control.  I was wondering how are these 'threads' used in UNIX?
Question by:Higante
    LVL 45

    Accepted Solution

    Hi Higante,

    Threads are used when a program needs simultaneous processes, usually running with common memory and/or data.

    One of the best examples is GUI programming.  The GUI needs a thread to monitor the objects on the GUI (buttons, edit boxes, etc.) and another thread to do whatever work the program is to do.  To try and do this with a single thread would mean that the program would have to interrupt itself to check for input from the GUI or the program would have to perform the checks at regular intervals through whatever loop it is executing.  Much easier to program this via threads.  Then each thread is coded to perform exactly what it should be doing.

    Another good use is applications that can take advantage of multiple CPUs.  All of the major DBMS engines mult-threads and take advantage of multiple CPUs when available.  Another great example is communications programs.  One thread performs the network I/O and another thread does other "stuff".

    There's lots of places where multi threading is the way to go.

    Good Luck!

    Author Comment


    Thanks for the good explanation.
    LVL 17

    Expert Comment

    Hi Kdo,

    I know this is answered but I wanted to add in another example.  A Classic Example!
    A multi-threaded server, one that can have multiple clients connected to it.  All it does is accept() a new socket, create a thread with that socket and go back to waiting to accept() a new socket.  That new thread does ALL the work associated with the client!!!  In this way a single server can have many many clients connected to it, because everything is being done in those threads!

    Joe P

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
    Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now