Background Thread vs. Foreground Thread

Instructor: David Gloag

David has over 40 years of industry experience in software development and information technology and a bachelor of computer science

The ability to run more than one program at once is important for computers today. In this lesson, we'll take a look at the thread, what it is, what background and foreground means with respect to them, and why they are important.

Doing More with Computers

As a society, we constantly strive to do more. If we make one hundred widgets a day in our factories, we want to make one hundred and fifty. If we lose five pounds this week on our weight loss program, we want to lose six the next.

It seems that we are built this way. So it makes sense that we would apply this thinking to computer processing as well. But how do we do that? How do we do more with our computers? There are many possible methods, some more effective than others. But there is arguably none more important than the thread.

What is a Thread?

In computer science, thread is short for thread-of-execution. It is some interval of processing that can be performed within a computer, and is often used interchangeably with the terms 'task' or 'process', but a thread is in fact different from these terms.

A thread is what gives a task or process life. Consider your vehicle for a moment. If we equate it to a process, then that process is transportation from point A to point B. Continuing on this line of thought, a thread would be you, what the vehicle needs to actually go anywhere. You provide the life necessary for your vehicle to accomplish anything important. The same is true for tasks, processes and threads.

What is a Background Thread?

A background thread is a thread that doesn't have complete focus at the moment. By focus, we mean processor time. In other words, it isn't processing as quickly, or it isn't processing at all. This can happen for a couple of reasons:

  1. Lower Priority - the background thread has a lower priority than the other threads currently engaged. Think of this like a band's background singers. They are there, sometimes participating, sometimes not. But they are not the primary focus of the group.

  2. Waiting for an External Event - At various times during the execution of a thread, it will require an event to occur before it can complete, like hard drive access. The thread sits idly in the background waiting. Think of this like a customer in a food line. They place an order, then wait off to the side until the order is ready. While this is happening, the line continues to move.

Or some combination of these two.

What is a Foreground Thread?

In contrast, a foreground thread is a thread that has a high percentage of the focus for any particular moment. This means that it spends more of its time executing. Using the band example from above, a foreground thread would be equivalent to the lead singer.

Foreground threads typically have higher priorities, and nothing that is causing them to wait. We say typically, because the low priority threads do get time to execute occasionally, and high priority threads do have to wait for external events at times.

To unlock this lesson you must be a Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use

Become a member and start learning now.
Become a Member  Back
What teachers are saying about
Try it now
Create an account to start this course today
Used by over 30 million students worldwide
Create an account