diff --git a/src/platform/pte.rs b/src/platform/pte.rs
index bcbae4888fbb213872585259bc159bf98f368b40..bcaf908b67f681c6ede816af638a56ca41cf6972 100644
--- a/src/platform/pte.rs
+++ b/src/platform/pte.rs
@@ -340,12 +340,13 @@ pub unsafe extern "C" fn pte_osSemaphorePend(
 ) -> pte_osResult {
     //TODO: pTimeout
     let semaphore = &mut *handle;
-    let mut acquired = false;
-    while !acquired {
-        let _guard = semaphore.lock.lock();
-        if intrinsics::atomic_load(&semaphore.count) > 0 {
-            intrinsics::atomic_xsub(&mut semaphore.count, 1);
-            acquired = true;
+    loop {
+        {
+            let _guard = semaphore.lock.lock();
+            if intrinsics::atomic_load(&semaphore.count) > 0 {
+                intrinsics::atomic_xsub(&mut semaphore.count, 1);
+                break;
+            }
         }
         Sys::sched_yield();
     }