# Threads and Polling

> UCall for Mojo

The binding starts no threads and keeps no queues; the application polls every event loop, batch endpoint and client on threads it owns.
A route handler runs on the thread inside `take_call` or `take_calls` for its event loop, and a batch handler on the thread inside `take_batches` for its endpoint.
On the polling thread nothing arrives while a handler runs, so a pull finding nothing there raises `WOULD_BLOCK` instead of waiting, and a streamed body is read from another thread.

`from ucall import Polling, CPUClass`

## Polling

What [`Server.take_call`](https://www.unum.cloud/docs/ucall/mojo/serving.md#take_call) found of its event loop. Binding-only.

```mojo
struct Polling
```

- `SERVING` = `Polling(Int32(0))`: The loop serves, or drains what it holds after a stop.
- `RETIRED` = `Polling(Int32(1))`: The loop drained or cut everything after [`Server.stop`](https://www.unum.cloud/docs/ucall/mojo/serving.md#stop), so a caller polling in slices stops.
- `code` `c_int`: Which of the two it is.

Conforms to: `Copyable`, `Deinitable`, `Equatable`, `ImplicitlyCopyable`, `Movable`, `RegisterPassable`, `TrivialRegisterPassable`

## CPUClass

A CPU kernel bundle, `ucall_cpu_class_t` in C. [`Library.cpu_class_name`](https://www.unum.cloud/docs/ucall/mojo/design.md#cpu_class_name) spells each one.

```mojo
struct CPUClass
```

- `UNKNOWN` = `CPUClass(Int32(0))`: No class requested: initialization picks the best class this machine runs.
- `SERIAL` = `CPUClass(Int32(1))`: Portable kernels with no SIMD, which every machine runs.
- `INTEL_HASWELL` = `CPUClass(Int32(2))`: AVX2 kernels, as on Intel Haswell.
- `INTEL_SKYLAKE` = `CPUClass(Int32(3))`: Adds AVX-512 kernels, as on Intel Skylake-X.
- `INTEL_ICELAKE` = `CPUClass(Int32(4))`: Adds Ice Lake's AVX-512 extensions and SHA.
- `INTEL_ALDER` = `CPUClass(Int32(5))`: AVX2 kernels with SHA and no AVX-512, as on Intel Alder Lake.
- `AWS_G2` = `CPUClass(Int32(6))`: NEON kernels with the AES and SHA extensions, as on AWS Graviton2.
- `AWS_G5` = `CPUClass(Int32(7))`: As on AWS Graviton5, running the kernels of [`AWS_G2`](#AWS_G2).
- `MONOVERSIONED` = `CPUClass(Int32(8))`: The one class a monoversioned build compiles, over every capability it targets.
- `code` `c_int`: The raw `ucall_cpu_class_t` value the ABI exchanges.

Conforms to: `Copyable`, `Deinitable`, `Equatable`, `ImplicitlyCopyable`, `Movable`, `RegisterPassable`, `TrivialRegisterPassable`

