<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 11.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 7.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "os",
  "identifier" : "/documentation/os/os_workgroup_set_working_arena",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "os"
    ],
    "preciseIdentifier" : "c:@F@os_workgroup_set_working_arena"
  },
  "title" : "os_workgroup_set_working_arena"
}
-->

# os_workgroup_set_working_arena

Distributes a block of managed memory to the threads of a workgroup.

```
extern int os_workgroup_set_working_arena(os_workgroup_t wg, void *arena, uint32_t max_workers, os_workgroup_working_arena_destructor_t destructor);
```

## Parameters

`wg`

The workgroup in which to store the shared data. The workgroup must not have any joined threads, and the workgroup must be idle.

`arena`

A pointer to the data you want to distribute among the workgroup’s threads. Specify `NULL` to remove any shared data from a workgroup.

`max_workers`

The maximum number of threads that may request a unique index from the workgroup. If your threads share all of the data, rather than operate on only part of that data, specify `0` for this parameter.

`destructor`

A function to deallocate the memory in the `arena` parameter.

## Return Value

`0` on success or an error code if the function encountered a problem. For example, the function returns `ENOMEM` if it is unable to allocate the memory it needs to manage the arena data.

## Discussion

Use this function to distribute a block of memory that you created to the threads of the workgroup. Configure the block of memory with the work that you want to those threads to perform. Call this function before you start an interval or parallel workgroup, and before you join any threads to the workgroup.

After assigning the arena data to the workgroup, join your threads and start your task. In each thread, call the [`os_workgroup_get_working_arena`](/documentation/os/os_workgroup_get_working_arena) function to retrieve the shared `arena` data, and optionally the thread’s unique index into that data. Unique indexes allow you to divide the `arena` data evenly among your threads. Each thread uses its index to access the appropriate portion of the data.

If you call this function more than once, each subsequent call uses the `destructor` function to clean up the previous arena data.

---

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)