---
title: os_workgroup_join
framework: os
role: symbol
role_heading: Function
path: os/os_workgroup_join
---

# os_workgroup_join

Adds the current thread to the specified workgroup.

## Declaration

```occ
extern int os_workgroup_join(os_workgroup_t wg, os_workgroup_join_token_t token_out);
```

## Parameters

- `wg`: The workgroup to join.
- `token_out`: An empty token structure. This function fills the provided structure with information about the workgroup relationship. Save this structure so you can remove the thread from the workgroup later.

## Return Value

Return Value A value of 0 on success, or a nonzero error code that indicates why the function failed. Common error codes include EINVAL or EALREADY. For example, this method returns EALREADY if the thread already belongs to a workgroup. It returns EINVAL if the workgroup is already canceled.

## Discussion

Discussion When you call this function, the current thread must not belong to any workgroup. This function adds the thread to the specified workgroup and updates the token_out parameter. You may call this function safely from a real-time thread of your app. important: Save the token_out parameter so that you can remove the thread from the workgroup later. When removing a thread, the thread, workgroup, and token data must match the original values you specify for this function; if they don’t, the system aborts your process.

## See Also

### Thread Attachment

- [os_workgroup_leave](os/os_workgroup_leave.md)
- [os_workgroup_join_token_t](os/os_workgroup_join_token_t.md)
