How do you access static variables in a thread-safe manner?

PORT_NR.fetch_add(1, Ordering::SeqCst) as u16 + 9090

The simpler option is to bind to port 0 and have the kernel choose an available one for you.

6 Likes