Initial project import

This commit is contained in:
Agila Forge Importer committed 2026-07-13 15:20:32 +00:00
commit 23f2d29e32
11957 files changed
+1754577

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
import sync
struct Counter {
pub mut:
i int
}
fn write_10000(mut co Counter, mut mx sync.Mutex) {
mx.lock()
co.i = 10000
mx.unlock()
}
fn test_mutex() {
mut co := &Counter{10086}
mut mx := sync.new_mutex()
mx.lock()
co.i = 888
th := spawn write_10000(mut co, mut mx)
mx.unlock() // after mx unlock, thread write_10000 can continue
th.wait()
mx.destroy()
assert co.i == 10000
}
fn test_try_lock_mutex() {
// In Windows, try_lock only avalible after Windows 7
$if windows {
$if !windows_7 ? {
return
}
}
mut mx := sync.new_mutex()
mx.lock()
try_fail := mx.try_lock()
assert try_fail == false
mx.unlock()
try_success := mx.try_lock()
assert try_success == true
mx.unlock() // you must unlock it, after try_lock success
mx.destroy()
}