---
title: cancel()
framework: foundation
role: symbol
role_heading: Instance Method
path: foundation/thread/cancel()
---

# cancel()

Changes the cancelled state of the receiver to indicate that it should exit.

## Declaration

```swift
func cancel()
```

## Discussion

Discussion The semantics of this method are the same as those used for Operation. This method sets state information in the receiver that is then reflected by the isCancelled property. Threads that support cancellation should periodically call the isCancelled method to determine if the thread has in fact been cancelled, and exit if it has been. For more information about cancellation and operation objects, see Operation.

## See Also

### Related Documentation

- [isCancelled](foundation/thread/iscancelled.md)

### Stopping a Thread

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