---
name: "libwget-thread"
section: "3"
platform: "linux"
package: "wget2-dev"
version: "2.2.0+ds-1+deb13u1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/libwget-thread"
---

# libwget-thread(3)

Implementation of multi-threading basic functionality

## NAME

libwget-thread - Implementation of multi-threading basic functionality

## SYNOPSIS

### Data Structures

struct **wget\_thread\_st**\
 struct **wget\_thread\_mutex\_st**\
 struct **wget\_thread\_cond\_st**\

### Functions

int **wget\_thread\_mutex\_init** (**wget\_thread\_mutex** \*mutex)\
 int **wget\_thread\_mutex\_destroy** (**wget\_thread\_mutex** \*mutex)\
 void **wget\_thread\_mutex\_lock** (**wget\_thread\_mutex** mutex)\
 void **wget\_thread\_mutex\_unlock** (**wget\_thread\_mutex** mutex)\
 int **wget\_thread\_cond\_init** (**wget\_thread\_cond** \*cond)\
 int **wget\_thread\_cond\_destroy** (**wget\_thread\_cond** \*cond)\
 int **wget\_thread\_cond\_signal** (**wget\_thread\_cond** cond)\
 int **wget\_thread\_cond\_wait** (**wget\_thread\_cond** cond, **wget\_thread\_mutex** mutex, long long ms)\
 int **wget\_thread\_start** (**wget\_thread** \*thread, void \*(\*start\_routine)(void \*), void \*arg, WGET\_GCC\_UNUSED int flags)\
 int **wget\_thread\_cancel** (WGET\_GCC\_UNUSED **wget\_thread** thread)\
 int **wget\_thread\_kill** (WGET\_GCC\_UNUSED **wget\_thread** thread, WGET\_GCC\_UNUSED int sig)\
 int **wget\_thread\_join** (**wget\_thread** \*thread)\
 wget\_thread\_id **wget\_thread\_self** (void)\
 bool **wget\_thread\_support** (void)\

## Detailed Description

This is a wrapper around Gnulib's glthread functionality.

It currently supports Posix threads (pthreads), GNU Pth threads, Solaris threads and Windows threads.

## Function Documentation

### int wget\_thread\_mutex\_init (wget\_thread\_mutex \* mutex)

**Parameters**

*mutex* The mutex to initialize

**Returns**

0 on success, non-zero on failure

Initializes the `mutex`.

After usage, a call to **wget\_thread\_mutex\_destroy()** frees the allocated resources.

### int wget\_thread\_mutex\_destroy (wget\_thread\_mutex \* mutex)

**Parameters**

*mutex* The mutex to destroy

**Returns**

0 on success, non-zero on failure

Free's the `mutex` and it's resources.

After calling this function, the `mutex` cannot be used any more.

### void wget\_thread\_mutex\_lock (wget\_thread\_mutex mutex)

**Parameters**

*mutex* The mutex to be locked

Creates a lock on the `mutex`.

To unlock the `mutex`, call **wget\_thread\_mutex\_unlock()**.

### void wget\_thread\_mutex\_unlock (wget\_thread\_mutex mutex)

**Parameters**

*mutex* The mutex to be unlocked

Unlocks the `mutex`.

### int wget\_thread\_cond\_init (wget\_thread\_cond \* cond)

**Parameters**

*cond* The conditional to initialize

**Returns**

0 on success, non-zero on failure

Initializes the conditional `cond`.

After usage, a call to **wget\_thread\_cond\_destroy()** frees the allocated resources.

### int wget\_thread\_cond\_destroy (wget\_thread\_cond \* cond)

**Parameters**

*cond* The conditional to destroy

**Returns**

0 on success, non-zero on failure

Free's the conditional `cond` and it's resources.

After calling this function, `cond` cannot be used any more.

### int wget\_thread\_cond\_signal (wget\_thread\_cond cond)

**Parameters**

*cond* The conditional to signal a condition

**Returns**

0 on success, non-zero on failure

Wakes up one (random) thread that waits on the conditional.

### int wget\_thread\_cond\_wait (wget\_thread\_cond cond, wget\_thread\_mutex mutex, long long ms)

**Parameters**

*cond* The conditional to wait for \
 *mutex* The mutex needed for thread-safety \
 *ms* The wait timeout in milliseconds

**Returns**

0 on success, non-zero on failure

Waits for a condition with a max. timeout of `ms` milliseconds.

To wait forever use a timeout lower or equal then 0.

### int wget\_thread\_start (wget\_thread \* thread, void \*(\*)(void \*) start\_routine, void \* arg, WGET\_GCC\_UNUSED int flags)

**Parameters**

*thread* The thread variable to be initialized \
 *start\_routine* The thread function to start \
 *arg* The argument given to `start_routine` \
 *flags* Currently unused

**Returns**

0 on success, non-zero on failure

Start `start_routine` as own thread with argument `arg`.

### int wget\_thread\_cancel (WGET\_GCC\_UNUSED wget\_thread thread)

**Parameters**

*thread* Thread to cancel

**Returns**

0 on success, non-zero on failure

Currently a no-op function, since it's not portable.

### int wget\_thread\_kill (WGET\_GCC\_UNUSED wget\_thread thread, WGET\_GCC\_UNUSED int sig)

**Parameters**

*thread* Thread to send the signal to \
 *sig* Signal to send

**Returns**

0 on success, non-zero on failure

Currently a no-op function, since it's not portable.

### int wget\_thread\_join (wget\_thread \* thread)

**Parameters**

*thread* Thread to wait for

**Returns**

0 on success, non-zero on failure

Wait until the `thread` has been stopped.

This function just waits - to stop a thread you have take your own measurements.

### wget\_thread\_id wget\_thread\_self (void)

**Returns**

The thread id of the caller.

### bool wget\_thread\_support (void)

**Returns**

Whether libwget supports multi-threading on this platform or not.

## Author

Generated automatically by Doxygen for wget2 from the source code.
