Skip to content

Instantly share code, notes, and snippets.

@technoscavenger
Created January 7, 2024 21:22
Show Gist options
  • Save technoscavenger/cbd918f8d9912ee95f022a4f797d022e to your computer and use it in GitHub Desktop.
Save technoscavenger/cbd918f8d9912ee95f022a4f797d022e to your computer and use it in GitHub Desktop.
use windows::{core::Result, Win32::System::Threading::*};
static COUNTER: std::sync::RwLock<i32> = std::sync::RwLock::new(0);
fn main() -> Result<()>{
unsafe {
let work = CreateThreadpoolWork(Some(callback), None, None)?;
for _ in 0..10 {
SubmitThreadpoolWork(work);
}
WaitForThreadpoolWorkCallbacks(work, false);
}
let counter = COUNTER.read().unwrap();
println!("counter: {}", *counter);
Ok(())
}
extern "system" fn callback(_: PTP_CALLBACK_INSTANCE, _: *mut std::ffi::c_void, _: PTP_WORK) {
let mut counter = COUNTER.write().unwrap();
*counter += 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment