# Threads and Polling

> The interface starts no threads and needs no runtime: every callback runs on a thread the application gave to a polling call.

`#include <ucall/types.hpp>` 1.0.0-rc.1 · b7577426

The interface starts no threads and needs no runtime: every callback runs on a thread the application gave to a polling call.

- A route handler runs on the thread inside `take_call` or `take_calls` for the event loop that received the request.
- A `pooled_batch` handler runs on the thread inside `take_batch` or `take_batches` for its endpoint, never on an event loop, while a `local_batch` handler runs inside `take_call` or `take_calls` for the loop whose requests it holds.
- A server’s peer authorizer runs on the polling thread completing the handshake, and a client’s on the client’s own thread inside `take_completed` or a blocking call.
- A deferred reply or pull finishes as its event loop polls, so its awaiter re-polls through the caller’s scheduler on that same thread.

Each event loop and each batch endpoint has one polling owner at a time. `take_calls` and `take_batches` run until `server_t::stop`, while `take_call` and `take_batch` return after one round, waiting up to their timeout, so a loop of them interleaves polling with other work, such as a scheduler’s posted polls. `server_t::stop` works from any thread, handlers included, and wakes every polling thread. The first stop drains, answering every request already held before its connection closes, and a second one cuts the replies still in flight. A client bound to a server through `client_options_t::server` advances only as that loop polls, so it is used on that loop’s thread, and its blocking calls would wait forever there. Every thread that polls, replies or reads must run on a CPU supporting the CPU class the server or client resolved at start, so `ucall_cpu_class_serial_k` is the safe choice on machines mixing CPU generations.

## API

### Functions

#### `cpu_class_name`

The stable name of a CPU kernel class, such as "intel-icelake".

[types.hpp:325 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L325)

```cpp
std::string_view cpu_class_name(ucall_cpu_class_t cpu_class) noexcept;
```

#### `cpu_class_from_name`

Reads a CPU kernel class back from its stable name, "unknown" included.

[types.hpp:328 ↗](https://github.com/unum-cloud/UCall/blob/b75774266a108d8a1b1a6db1489f8a7141c556df/cpp/ucall/types.hpp#L328)

```cpp
expected<ucall_cpu_class_t> cpu_class_from_name(
    std::string_view name) noexcept;
```
