ion7-core / threadpool

class

ion7.core.Threadpool

_ptr cdata `ggml_threadpool_t` opaque handle.
_n integer Worker thread count, cached at creation.

Functions

Threadpool.new

Create a CPU threadpool with `n_threads` worker threads.

Threadpool.new(n_threads)
n_threadsintegerWorker count (must be > 0).
→ ion7.core.Threadpool

raises — When `n_threads` is invalid or `ggml_threadpool_new` fails.

Threadpool:ptr

Return the raw `ggml_threadpool_t` cdata pointer for use with `Context:attach_threadpool` (or any other ggml API that wants one).

Threadpool:ptr()
→ cdata

Threadpool:n_threads

Return the cached worker count. Cheap : avoids the FFI roundtrip of `ggml_threadpool_get_n_threads`. The value never changes after construction so caching is exact.

Threadpool:n_threads()
→ integer

Threadpool:pause

Pause every worker thread. Workers stop accepting new jobs until `resume` is called. No-op when the pool is already freed.

Threadpool:pause()

Threadpool:resume

Resume previously paused workers. No-op when the pool is freed.

Threadpool:resume()

Threadpool:free

Manually release the threadpool's native resources. Idempotent — safe to call multiple times. The `ffi.gc` finalizer is disarmed BEFORE the explicit free so the GC does not double-free the same pointer later.

Threadpool:free()