---
title: Thread
framework: foundation
role: symbol
role_heading: Class
path: foundation/thread
---

# Thread

A thread of execution.

## Declaration

```swift
class Thread
```

## Overview

Overview Use this class when you want to have an Objective-C method run in its own thread of execution. Threads are especially useful when you need to perform a lengthy task, but don’t want it to block the execution of the rest of the application. In particular, you can use threads to avoid blocking the main thread of the application, which handles user interface and event-related actions. Threads can also be used to divide a large job into several smaller jobs, which can lead to performance increases on multi-core computers. The Thread class supports semantics similar to those of Operation for monitoring the runtime condition of a thread. You can use these semantics to cancel the execution of a thread or determine if the thread is still executing or has finished its task. Canceling a thread requires support from your thread code; see the description for cancel() for more information. Subclassing Notes You can subclass Thread and override the main() method to implement your thread’s main entry point. If you override main(), you do not need to invoke the inherited behavior by calling super.

## Topics

### Initializing an NSThread Object

- [init()](foundation/thread/init().md)
- [init(target:selector:object:)](foundation/thread/init(target:selector:object:).md)

### Starting a Thread

- [detachNewThreadSelector(_:toTarget:with:)](foundation/thread/detachnewthreadselector(_:totarget:with:).md)
- [start()](foundation/thread/start().md)
- [main()](foundation/thread/main().md)

### Stopping a Thread

- [sleep(until:)](foundation/thread/sleep(until:).md)
- [sleep(forTimeInterval:)](foundation/thread/sleep(fortimeinterval:).md)
- [exit()](foundation/thread/exit().md)
- [cancel()](foundation/thread/cancel().md)

### Determining the Thread’s Execution State

- [isExecuting](foundation/thread/isexecuting.md)
- [isFinished](foundation/thread/isfinished.md)
- [isCancelled](foundation/thread/iscancelled.md)

### Working with the Main Thread

- [isMainThread](foundation/thread/ismainthread-swift.type.property.md)
- [isMainThread](foundation/thread/ismainthread-swift.property.md)
- [main](foundation/thread/main.md)

### Querying the Environment

- [isMultiThreaded()](foundation/thread/ismultithreaded().md)
- [current](foundation/thread/current.md)
- [callStackReturnAddresses](foundation/thread/callstackreturnaddresses.md)
- [callStackSymbols](foundation/thread/callstacksymbols.md)

### Working with Thread Properties

- [threadDictionary](foundation/thread/threaddictionary.md)
- [NSAssertionHandlerKey](foundation/nsassertionhandlerkey.md)
- [name](foundation/thread/name.md)
- [stackSize](foundation/thread/stacksize.md)

### Prioritizing Thread Work

- [qualityOfService](foundation/thread/qualityofservice.md)
- [QualityOfService](foundation/qualityofservice.md)
- [threadPriority()](foundation/thread/threadpriority().md)
- [threadPriority](foundation/thread/threadpriority.md)
- [setThreadPriority(_:)](foundation/thread/setthreadpriority(_:).md)

### Notifications

- [NSDidBecomeSingleThreaded](foundation/nsnotification/name-swift.struct/nsdidbecomesinglethreaded.md)
- [NSThreadWillExit](foundation/nsnotification/name-swift.struct/nsthreadwillexit.md)
- [NSWillBecomeMultiThreaded](foundation/nsnotification/name-swift.struct/nswillbecomemultithreaded.md)

### Initializers

- [init(block:)](foundation/thread/init(block:).md)

### Type Methods

- [detachNewThread(_:)](foundation/thread/detachnewthread(_:).md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)

## See Also

### Threads and Locking

- [NSLocking](foundation/nslocking.md)
- [NSLock](foundation/nslock.md)
- [NSRecursiveLock](foundation/nsrecursivelock.md)
- [NSDistributedLock](foundation/nsdistributedlock.md)
- [NSConditionLock](foundation/nsconditionlock.md)
- [NSCondition](foundation/nscondition.md)
