---
name: "thr_new"
section: "2"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/thr_new"
---

# thr\_new(2)

create new thread of execution

## NAME

**thr\_new** – create new thread of execution

## LIBRARY

Standard C Library (libc, -lc)

## SYNOPSIS

**#include \<sys/thr.h\>**

*int*\

**thr\_new**(*struct thr\_param \*param*, *int param\_size*);

## DESCRIPTION

This function is intended for implementing threading. Normal applications should call [pthread\_create(3)](/pthread_create/3.md) instead.

The **thr\_new**() system call creates a new kernel-scheduled thread of execution in the context of the current process. The newly created thread shares all attributes of the process with the existing kernel-scheduled threads in the process, but has private processor execution state. The machine context for the new thread is copied from the creating thread's context, including coprocessor state. FPU state and specific machine registers are excluded from the copy. These are set according to ABI requirements and syscall parameters. The FPU state for the new thread is reinitialized to clean.

The *param* structure supplies parameters affecting the thread creation. The structure is defined in the ⟨sys/thr.h⟩ header as follows

```
struct thr_param {
    void          (*start_func)(void *);
    void          *arg;
    char          *stack_base;
    size_t        stack_size;
    char          *tls_base;
    size_t        tls_size;
    long          *child_tid;
    long          *parent_tid;
    int           flags;
    struct rtprio *rtp;
};
```

and contains the following fields:

- *start\_func*

  Pointer to the thread entry function. The kernel arranges for the new thread to start executing the function upon the first return to userspace.

- *arg*

  Opaque argument supplied to the entry function.

- *stack\_base*

  Stack base address. The stack must be allocated by the caller. On some architectures, the ABI might require that the system put information on the stack to ensure the execution environment for *start\_func*.

- *stack\_size*

  Stack size.

- *tls\_base*

  TLS base address. The value of TLS base is loaded into the ABI-defined machine register in the new thread context.

- *tls\_size*

  TLS size.

- *child\_tid*

  Address to store the new thread identifier, for the child's use.

- *parent\_tid*

  Address to store the new thread identifier, for the parent's use.

  Both *child\_tid* and *parent\_tid* are provided, with the intent that *child\_tid* is used by the new thread to get its thread identifier without issuing the [thr\_self(2)](/thr_self/2.md) syscall, while *parent\_tid* is used by the thread creator. The latter is separate from *child\_tid* because the new thread might exit and free its thread data before the parent has a chance to execute far enough to access it.

- *flags*

  Thread creation flags. The *flags* member may specify the following flags:

  - THR\_SUSPENDED

    Create the new thread in the suspended state. The flag is not currently implemented.

  - THR\_SYSTEM\_SCOPE

    Create the system scope thread. The flag is not currently implemented.

  - THR\_C\_RUNTIME

    Indicate that the new thread is created by the C language runtime. It has architecture-specific meaning.

    On amd64, the flag requests that the specified *tls\_base* was loaded into the *%fsbase* register before calling a signal handler.

- *rtp*

  Real-time scheduling priority for the new thread. May be NULL to inherit the priority from the creating thread.

The *param\_size* argument should be set to the size of the *param* structure.

After the first successful creation of an additional thread, the process is marked by the kernel as multi-threaded. In particular, the P\_HADTHREADS flag is set in the process' p\_flag (visible in the [ps(1)](/ps/1.md) output), and several operations are executed in multi-threaded mode. For instance, the [execve(2)](/execve/2.md) system call terminates all threads but the calling one on successful execution.

## RETURN VALUES

If successful, **thr\_new**() will return zero, otherwise -1 is returned, and *errno* is set to indicate the error.

## ERRORS

The **thr\_new**() operation returns the following errors:

- \[EFAULT\]

  The memory pointed to by the *param* argument is not valid.

- \[EFAULT\]

  The memory pointed to by the *param* structure *child\_tid*, *parent\_tid*, or *rtp* arguments is not valid.

- \[EFAULT\]

  The specified stack base is invalid, or the kernel was unable to put required initial data on the stack.

- \[EINVAL\]

  The *param\_size* argument specifies a negative value, or the value is greater than the largest *struct*, *param* size the kernel can interpret.

- \[EINVAL\]

  The *rtp* member is not NULL and specifies invalid scheduling parameters.

- \[EINVAL\]

  The specified TLS base is invalid.

- \[EPERM\]

  The caller does not have permission to set the scheduling parameters or scheduling policy.

- \[EPROCLIM\]

  Creation of the new thread would exceed the RACCT\_NTHR limit, see [rctl\_get\_racct(2)](/rctl_get_racct/2.md).

- \[EPROCLIM\]

  Creation of the new thread would exceed the kern.threads.max\_threads\_per\_proc [sysctl(3)](/sysctl/3.md) limit.

- \[ENOMEM\]

  There was not enough kernel memory to allocate the new thread structures.

## SEE ALSO

[ps(1)](/ps/1.md), [\_umtx\_op(2)](/_umtx_op/2.md), [execve(2)](/execve/2.md), [rctl\_get\_racct(2)](/rctl_get_racct/2.md), [thr\_exit(2)](/thr_exit/2.md), [thr\_kill(2)](/thr_kill/2.md), [thr\_kill2(2)](/thr_kill2/2.md), [thr\_self(2)](/thr_self/2.md), [thr\_set\_name(2)](/thr_set_name/2.md), [pthread\_create(3)](/pthread_create/3.md)

## STANDARDS

The **thr\_new**() system call is non-standard and is used by the library “libthr” to implement IEEE Std 1003.1-2001 (“POSIX.1”) [pthread(3)](/pthread/3.md) functionality.

## HISTORY

The **thr\_new**() system call first appeared in FreeBSD 5.2.
