<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.5.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/Thread/cancel()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSThread(im)cancel"
  },
  "title" : "cancel()"
}
-->

# cancel()

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

```
func cancel()
```

## Discussion

The semantics of this method are the same as those used for [`Operation`](/documentation/Foundation/Operation). This method sets state information in the receiver that is then reflected by the [`isCancelled`](/documentation/Foundation/Thread/isCancelled) property. Threads that support cancellation should periodically call the [`isCancelled`](/documentation/Foundation/Thread/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`](/documentation/Foundation/Operation).

## See Also

[`isCancelled`](/documentation/Foundation/Thread/isCancelled)

A Boolean value that indicates whether the receiver is cancelled.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)