• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 485
  • Last Modified:

What are threads for in UNIX?

I know that 'Threads' defines interfaces and functionality to support multiple flows of control.  I was wondering how are these 'threads' used in UNIX?
1 Solution
Kent OlsenData Warehouse Architect / DBACommented:
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!
HiganteAuthor Commented:

Thanks for the good explanation.
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

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now