---
name: "xs_init"
section: "3"
platform: "linux"
package: "libxs-dev"
version: "1.2.0-2"
release: "Debian 10 (Buster)"
platforms: ["linux"]
url: "https://new.carta.tech/xs_init"
---

# xs\_init(3)

initialise Crossroads context

## NAME

xs\_init - initialise Crossroads context

## SYNOPSIS

**void \*xs\_init ();**

## DESCRIPTION

The *xs\_init()* function initialises a Crossroads *context*.

**Thread safety**. A *context* is thread safe and may be shared among as many application threads as necessary, without any additional locking required on the part of the caller.

The individual *sockets* within a *context* are *not* thread safe — applications may *not* use a single *socket* concurrently from multiple threads.

A *socket* *may* be *migrated* from one thread to another, by issuing a full memory barrier between individual calls on the *socket*. For example, this means applications can create a socket in one thread with *xs\_socket()* and then pass it to a *newly created* thread as part of thread initialization via a structure passed as an argument to *pthread\_create()*.

**Context options**. Context options may be set prior to creating the first socket within a *context*, using the *xs\_setctxopt()* function. See [**xs\_setctxopt**(3)](/xs_setctxopt/3.md) for details on the available context options.

**Multiple contexts**. Multiple *contexts* may coexist within a single application. Thus, an application can use Crossroads directly and at the same time make use of any number of additional libraries or components which themselves make use of Crossroads.

## RETURN VALUE

The *xs\_init()* function shall return an opaque handle to the initialised *context* if successful. Otherwise it shall return NULL and set *errno* to one of the values defined below.

## ERRORS

No error values are defined.

## SEE ALSO

[**xs**(7)](/xs/7.md) [**xs\_term**(3)](/xs_term/3.md) [**xs\_setctxopt**(3)](/xs_setctxopt/3.md)

## AUTHORS

The Crossroads documentation was written by Martin Sustrik \<**sustrik@250bpm.com**\[1\]\> and Martin Lucina \<**martin@lucina.net**\[2\]\>.

## NOTES

- 1\.

  sustrik@250bpm.com

  mailto:sustrik@250bpm.com

- 2\.

  martin@lucina.net

  mailto:martin@lucina.net
