### Function

# GLib atomic_int_exchange

since: 2.74

#### Declaration

    gint
    g_atomic_int_exchange (
      gint* atomic,
      gint newval
    )

#### Description

Sets the `atomic` to `newval` and returns the old value from `atomic`.

This exchange is done atomically.

Think of this operation as an atomic version of `{ tmp = *atomic; *atomic = val; return tmp; }`.

This call acts as a full compiler and hardware memory barrier.

Available since: 2.74

#### Parameters

`atomic`

  Type: `gint*`

  A pointer to a #gint or #guint.

  The data is owned by the caller of the function.

`newval`

  Type: `gint`

  The value to replace with.

#### Return value

Type: `gint`

The value of `atomic` before the exchange, signed.