Marcel Taeumel uploaded a new version of KernelTests to project The Trunk: http://source.squeak.org/trunk/KernelTests-jar.436.mcz
==================== Summary ====================
Name: KernelTests-jar.436 Author: jar Time: 20 June 2022, 6:16:50.946618 pm UUID: e028fc29-0d67-2840-b4cf-be8269e69fc3 Ancestors: KernelTests-ct.435
Add semaphore and mutex tests for #suspend vs #suspendAndUnblock semantics
=============== Diff against KernelTests-ct.435 ===============
Item was added: + ----- Method: MutexTest>>testSuspendAndResume (in category 'tests') ----- + testSuspendAndResume "self run: #testSuspendAndResume" + "Test the semantics of suspending and resuming a process blocked on a mutex; + Note the difference between #suspend and #suspendAndUnblock. + Note: this test will fail when run with older VMs without primitive suspend 578." + + | lock sock proc wait | + lock := Mutex new. + sock := Semaphore new. + proc := [lock critical: [sock wait]] fork. + wait := [lock critical: []] fork. + Processor yield. + self assert: proc suspendingList == sock. + self assert: wait suspendingList == lock. + self deny: lock isEmpty. + self assert: lock isOwned. + wait suspend; resume. + "wait returned back to the mutex" + Processor yield. + self assert: wait isBlocked. + self assert: proc suspendingList == sock. + self assert: wait suspendingList == lock. + self deny: lock isEmpty. + self assert: lock isOwned. + + "now the same with suspendAndUnblock" + lock := Mutex new. + sock := Semaphore new. + proc := [lock critical: [sock wait]] fork. + wait := [lock critical: []] fork. + Processor yield. + self assert: proc suspendingList == sock. + self assert: wait suspendingList == lock. + self deny: lock isEmpty. + self assert: lock isOwned. + wait suspendAndUnblock; resume. + "wait unblocked from the mutex BUT..." + Processor yield. + self assert: wait isTerminated. + self assert: proc suspendingList == sock. + self assert: wait suspendingList == nil. + self assert: lock isEmpty. + "... left this MESS behind:" + self deny: lock isOwned + "Indeed, lock should have stayed owned; + this is why primitive 88 is so dangerous"!
Item was added: + ----- Method: SemaphoreTest>>testSuspendAndResume (in category 'tests') ----- + testSuspendAndResume + "Test the semantics of suspending and resuming a process blocked on a semaphore; + Note the difference between #suspend and #suspendAndUnblock. + Note: this test will fail when run with older VMs without primitive suspend 578." + + | p | + p := [Semaphore new wait] fork. + Processor yield. + p suspend; resume. + "suspend removes p from the semaphore but backs up its pc; + hence when resumed p reenters the wait state" + Processor yield. + self assert: p isBlocked. + + p := [Semaphore new wait] fork. + Processor yield. + p suspendAndUnblock; resume. + "suspendAndUnblock just removes p from the semaphore; + hence when resumed p simply proceeds" + Processor yield. + self assert: p isTerminated!
packages@lists.squeakfoundation.org