---
name: "iv_task"
section: "3"
platform: "linux"
package: "libivykis-dev"
version: "0.43.2-1+b1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/iv_task"
---

# iv\_task(3)

deal with ivykis tasks

## NAME

iv\_task\_register, iv\_task\_unregister, iv\_task\_registered - deal with ivykis tasks

## SYNOPSIS

**#include \<iv.h\>**

```
struct iv_task {
        void            *cookie;
        void            (*handler)(void *);
};
```

**void IV\_TASK\_INIT(struct iv\_task \****task***);**\
 **void iv\_task\_register(struct iv\_task \****task***);**\
 **void iv\_task\_unregister(struct iv\_task \****task***);**\
 **int iv\_task\_registered(const struct iv\_task \****task***);**\

## DESCRIPTION

The functions **iv\_task\_register** and **iv\_task\_unregister** register, respectively unregister, a task with the current thread's ivykis event loop. **iv\_task\_registered** on a task returns true if that task is currently registered with ivykis.

A task is like a timer, but with an immediate timeout.  When a task is registered, unless it is unregistered again first, the callback function specified by **-\>handler** is guaranteed to be called once, in the thread that the task was registered in, some time after control returns to the ivykis main loop but before ivykis will sleep for more events, with **-\>cookie** as its first and sole argument.  When this happens, the task is transparently unregistered.

Tasks are mainly used for scheduling code for execution where it is not appropriate to directly run that code in the calling context (for example, because the current context might be run as a callback function where the caller expects certain conditions to remain invariant after the callback completes).

The application is allowed to change the **-\>cookie** and **-\>handler** members at any time.

A given **struct iv\_task** can only be registered in one thread at a time, and a task can only be unregistered in the thread that it was registered from.

There is no limit on the number of tasks registered at once.

See [**iv\_examples**(3)](/iv_examples/3.md) for programming examples.

## SEE ALSO

[**ivykis**(3)](/ivykis/3.md), [**iv\_examples**(3)](/iv_examples/3.md)
