Created
January 7, 2024 21:22
-
-
Save technoscavenger/cbd918f8d9912ee95f022a4f797d022e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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