# Counter

## NAME

counter - A semaphore-like object for synchronizing across processes

## SYNOPSIS

A counter is like an [event](https://fuchsia.dev/reference/kernel_objects/event), but with an integer that can be incremented,
decremented, read, or written.

## DESCRIPTION

Counter is a synchronization tool allowing processes to coordinate and
synchronize their actions. A counter contains a signed 64-bit integer and is
somewhat similar to a counting semaphore.

Counter is designed to be used with [`zx_object_wait_one()`](https://fuchsia.dev/reference/syscalls/object_wait_one),
[`zx_object_wait_many()`](https://fuchsia.dev/reference/syscalls/object_wait_many), or [`zx_object_wait_async()`](https://fuchsia.dev/reference/syscalls/object_wait_async).

## SIGNALS

In addition to the standard user signals (**ZX_USER_SIGNAL_0** through
**ZX_USER_SIGNAL_7**), counter has two signals that are automatically
asserted/deasserted based on the value:

**ZX_COUNTER_NON_POSITIVE** indicates the value is less than or equal to zero.

**ZX_COUNTER_POSITIVE** indicates the value is greater than or equal to zero.

## SYSCALLS

- [`zx_counter_create()`](https://fuchsia.dev/reference/syscalls/counter_create) - create a counter
- [`zx_counter_add()`](https://fuchsia.dev/reference/syscalls/counter_add) - add to a counter
- [`zx_counter_read()`](https://fuchsia.dev/reference/syscalls/counter_read) - read a counter's value
- [`zx_counter_write()`](https://fuchsia.dev/reference/syscalls/counter_write) - write a counter's value

[](https://issues.fuchsia.dev/issues/new?component=1439230&template=1881640&description=Issue+on:+https://fuchsia.dev/docs/reference/kernel_objects/counter.md "Report a bug or suggest improvements on this page") [](https://cs.opensource.google/fuchsia/fuchsia/+/main:docs/reference/kernel_objects/counter.md "View the source code of this page") [](https://ci.android.com/edit?repo=fuchsia/fuchsia/main&file=docs/reference/kernel_objects/counter.md&cloneRepo=fuchsia/fuchsia:refs/heads/main&fullPath=fuchsia/docs/reference/kernel_objects/counter.md "Edit the source code of this page")