# zx_counter_write

## Summary

Write a value to a counter.

## Declaration

    #include <zircon/syscalls.h>

    zx_status_t zx_counter_write(zx_handle_t handle, int64_t value);

## Description

`zx_counter_write()` writes *value* to the counter referenced by *handle* ,
asserting/deasserting signals as necessary. See [`zx_counter_add()`](https://fuchsia.dev/reference/syscalls/counter_add) for
the conditions on which signals are asserted/deasserted.

Because concurrent operations on a counter may be interleaved with one another,
an implementation of a "counting semaphore" synchronization protocol should use
`zx_counter_add()` instead of a sequence of `zx_counter_read()`, modify,
`zx_counter_write()`.

## Rights

*handle* must have `ZX_RIGHT_WRITE`.

## Return value

`zx_counter_write()` returns `ZX_OK` on success.

On failure, an error value is returned.

## Errors

`ZX_ERR_WRONG_TYPE` if *handle* is not a counter handle.

`ZX_ERR_ACCESS_DENIED` if *handle* does not have `ZX_RIGHT_WRITE`.

`ZX_ERR_INVALID_ARGS` if *value* is an invalid pointer.

## See also

- [`zx_object_wait_async()`](https://fuchsia.dev/reference/syscalls/object_wait_async)
- [`zx_object_wait_many()`](https://fuchsia.dev/reference/syscalls/object_wait_many)
- [`zx_object_wait_one()`](https://fuchsia.dev/reference/syscalls/object_wait_one)
- [`zx_counter_create()`](https://fuchsia.dev/reference/syscalls/counter_create)
- [`zx_counter_add()`](https://fuchsia.dev/reference/syscalls/counter_add)
- [`zx_counter_read()`](https://fuchsia.dev/reference/syscalls/counter_read)