pub fn initialize_multithreaded(threads: Option<NonZeroUsize>)Expand description
initialize, and start the threads that the multithreaded calls and
stream use: every program that makes such calls calls this once,
before them, in place of initialize. It starts threads - 1 workers,
and each multithreaded call hashes on its calling thread and the
workers (calls made at once share the workers), and on CPUs with SME2
(Apple M4) the SME2 thread too; None means one thread
a CPU (std::thread::available_parallelism, which follows the CPU
affinity the program runs under). With 1, calls hash on their calling
thread alone: no workers start, nor the SME2 thread. Otherwise it
starts the first worker and returns; the first worker starts the others
(each 20-30 us on Linux x86-64), and calls run on the workers started
so far. The
threads wait asleep whenever no call has work for them (their memory:
see Memory). Later calls return at once, and must ask
for the same number: another Some panics. A panic on a worker thread
(a bug in this crate) ends the process, its message printed, rather
than leaving the call that waits for that worker’s piece waiting
forever.
blake3_servil::initialize_multithreaded(None);
let hash = blake3_servil::hash_multithreaded(&[0u8; 1 << 20]);
assert_eq!(hash, blake3_servil::hash(&[0u8; 1 << 20]));