Frontier Tutorials / Working With Threads / What Are Threads?

What Are Threads?

The term thread is short for thread of execution.

It is a way of describing processes running in parallel within the same application.

Threads are a powerful tool, but can also be tricky. They are typically used to split a task into a number of subtasks that can run nearly independently, with a main thread or primary thread of execution waiting on their completion, then acting on the aggregate of their results.

The catch is the word nearly. It is often necessary to share resources (data values, functions, TCP streams, etc.) between different threads. Doing this without one thread interfering with another can be tricky. Semaphores allow threads to synchronize their use of shared resources.

It is also very easy for one process in a threaded application to keep all other processes from executing. This is called hogging the CPU. Threads must yield to allow other processes to run in parallel.

Semaphores and yielding the CPU are the next two topics in the tutorial.

Let's take a look at semaphores.

Tutorial Contents
Working With Threads
What Are Threads?
Semaphores--Traffic Control for Threads
How to Be Thread-Friendly
Rules of Thread Safety
An Example
Frontier's Thread Verbs
Thread Utilities
Glossary of Terms
About the Author