# AtomicSafetyHandle

> Coordinate safe access to native container memory inside the job system.

## Definition

* **Type:** Struct
* **Namespace:** [Unity.Collections.LowLevel.Unsafe](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe.md)
* **Assembly:** UnityEngine.CoreModule

```csharp
public struct AtomicSafetyHandle
```

## Remarks

`AtomicSafetyHandle` holds a reference to the central information that the safety system stores for a given native container. When a job contains a `NativeContainer` instance, the job system automatically configures the flags in `AtomicSafetyHandle` to reflect the way that the native container can be used in that job. Each job has a separate `AtomicSafetyHandle` instance for a given native container.

Use this class when you implement a custom `NativeContainer` type. Every `NativeContainer` instance must contain an `AtomicSafetyHandle` field named `m_Safety`.

For a conceptual overview of AtomicSafetyHandle and the role it plays in the job system, refer to [Implement a custom native container](/engine/6000.6/manual/scripting/optimization/job-system/thread-safe-types/custom-nativecontainer.md).

## Static Methods

| Method                                                                                                                                                                                               | Description                                                                                                                                                                                                                            |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [CheckDeallocateAndThrow](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/checkdeallocateandthrow.md)                                                           | Check if an AtomicSafetyHandle can be deallocated.                                                                                                                                                                                     |
| [CheckExistsAndThrow](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/checkexistsandthrow.md)                                                                   | Check if an AtomicSafetyHandle is valid.                                                                                                                                                                                               |
| [CheckGetSecondaryDataPointerAndThrow](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/checkgetsecondarydatapointerandthrow.md)                                 | Check whether it's safe to create a memory-aliasing view to a native container.                                                                                                                                                        |
| [CheckReadAndThrow](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/checkreadandthrow.md)                                                                       | Check whether the referenced native container can be read from.                                                                                                                                                                        |
| [CheckWriteAndBumpSecondaryVersion](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/checkwriteandbumpsecondaryversion.md)                                       | Check whether the referenced native container can be written to and increment the secondary version number if so.                                                                                                                      |
| [CheckWriteAndThrow](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/checkwriteandthrow.md)                                                                     | Check whether the referenced native container can be written to.                                                                                                                                                                       |
| [Create](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/create.md)                                                                                             | Creates a new AtomicSafetyHandle.                                                                                                                                                                                                      |
| [EnforceAllBufferJobsHaveCompleted](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/enforceallbufferjobshavecompleted.md)                                       | Waits for all jobs running against the [AtomicSafetyHandle](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle.md) to complete.                                                                      |
| [EnforceAllBufferJobsHaveCompletedAndDisableReadWrite](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/enforceallbufferjobshavecompletedanddisablereadwrite.md) | Waits for all jobs running against an [AtomicSafetyHandle](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle.md) to complete and then disables the read and write access on the AtomicSafetyHandle. |
| [EnforceAllBufferJobsHaveCompletedAndRelease](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/enforceallbufferjobshavecompletedandrelease.md)                   | Waits for all jobs running against an [AtomicSafetyHandle](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle.md) to complete and then releases the AtomicSafetyHandle.                              |
| [GetAllowReadOrWriteAccess](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/getallowreadorwriteaccess.md)                                                       | Checks if the [AtomicSafetyHandle](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle.md) is configured to allow reading or writing.                                                                 |
| [GetNestedContainer](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/getnestedcontainer.md)                                                                     | Checks whether an AtomicSafetyHandle represents a nested container.                                                                                                                                                                    |
| [GetReaderArray](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/getreaderarray.md)                                                                             | Fetches the job handles of all jobs that read from an AtomicSafetyHandle.                                                                                                                                                              |
| [GetReaderName](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/getreadername.md)                                                                               | Gets the name of a specified job that reads from an AtomicSafetyHandle.                                                                                                                                                                |
| [GetTempMemoryHandle](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/gettempmemoryhandle.md)                                                                   | Gets an AtomicSafetyHandle for the temporary memory allocations in a temporary memory scope.                                                                                                                                           |
| [GetTempUnsafePtrSliceHandle](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/gettempunsafeptrslicehandle.md)                                                   | Gets a single shared AtomicSafetyHandle.                                                                                                                                                                                               |
| [GetWriter](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/getwriter.md)                                                                                       | Gets any writers on an AtomicSafetyHandle.                                                                                                                                                                                             |
| [GetWriterName](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/getwritername.md)                                                                               | Gets the debug name of the current writer on an AtomicSafetyHandle.                                                                                                                                                                    |
| [IsDefaultValue](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/isdefaultvalue.md)                                                                             | Checks if an AtomicSafetyHandle has its default value.                                                                                                                                                                                 |
| [IsHandleValid](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/ishandlevalid.md)                                                                               | Checks if an AtomicSafetyHandle is valid.                                                                                                                                                                                              |
| [IsTempMemoryHandle](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/istempmemoryhandle.md)                                                                     | Checks if an AtomicSafetyHandle is the temporary memory safety handle for the active temporary memory scope.                                                                                                                           |
| [IsValidNonDefaultHandle](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/isvalidnondefaulthandle.md)                                                           | Checks if an AtomicSafetyHandle has been initialized and is valid.                                                                                                                                                                     |
| [NewStaticSafetyId](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/newstaticsafetyid.md)                                                                       | Allocates a new static safety ID to store information for the provided type.                                                                                                                                                           |
| [PrepareUndisposable](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/prepareundisposable.md)                                                                   | Marks an AtomicSafetyHandle so that it can't be disposed of.                                                                                                                                                                           |
| [Release](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/release.md)                                                                                           | Releases a previously created AtomicSafetyHandle.                                                                                                                                                                                      |
| [SetAllowReadOrWriteAccess](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/setallowreadorwriteaccess.md)                                                       | Sets the read or write access on an AtomicSafetyHandle.                                                                                                                                                                                |
| [SetAllowSecondaryVersionWriting](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/setallowsecondaryversionwriting.md)                                           | Sets whether other AtomicSafetyHandles that use a secondary version number can write to the NativeContainer protected by a given AtomicSafetyHandle.                                                                                   |
| [SetBumpSecondaryVersionOnScheduleWrite](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/setbumpsecondaryversiononschedulewrite.md)                             | Sets whether to automatically bump the secondary version when scheduling a job that has write access to the AtomicSafetyHandle.                                                                                                        |
| [SetCustomErrorMessage](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/setcustomerrormessage.md)                                                               | Provides a custom error message for a specific job debugger error type, in cases where additional context can be provided.                                                                                                             |
| [SetNestedContainer](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/setnestedcontainer.md)                                                                     | Sets the nested container flag on an AtomicSafetyHandle.                                                                                                                                                                               |
| [SetStaticSafetyId](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/setstaticsafetyid.md)                                                                       | Assigns a provided static safety ID to an [AtomicSafetyHandle](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle.md).                                                                               |
| [UseSecondaryVersion](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/usesecondaryversion.md)                                                                   | Switches the AtomicSafetyHandle to the secondary version number.                                                                                                                                                                       |
| [ValidateNonDefaultHandle](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/atomicsafetyhandle/validatenondefaulthandle.md)                                                         | Checks that the handle has been initialized, and if so, checks that it is still valid.                                                                                                                                                 |
