2016-03-28 13:27:03 +00:00
|
|
|
|
2017-01-09 12:52:37 +00:00
|
|
|
#include 'Moo.moo'.
|
2016-03-28 13:27:03 +00:00
|
|
|
|
|
|
|
#################################################################
|
|
|
|
## MAIN
|
|
|
|
#################################################################
|
|
|
|
|
2017-06-07 17:22:14 +00:00
|
|
|
class MyObject(Object)
|
2016-03-28 13:27:03 +00:00
|
|
|
{
|
2017-06-07 17:22:14 +00:00
|
|
|
var(#class) a := 100.
|
2016-03-28 13:27:03 +00:00
|
|
|
|
2017-06-07 17:22:14 +00:00
|
|
|
method(#class) proc1
|
2016-03-28 13:27:03 +00:00
|
|
|
{
|
2017-11-05 16:47:13 +00:00
|
|
|
[ System sleepForSecs: 1. a := a + 100 ] newProcess resume.
|
2017-06-07 17:22:14 +00:00
|
|
|
^a
|
2016-03-28 13:27:03 +00:00
|
|
|
}
|
|
|
|
|
2017-07-21 16:54:43 +00:00
|
|
|
method(#class) test_semaphore_heap
|
|
|
|
{
|
|
|
|
| sempq a |
|
|
|
|
sempq := SemaphoreHeap new.
|
|
|
|
|
|
|
|
'--------------------------' dump.
|
|
|
|
|
|
|
|
1 to: 200 by: 1 do: [ :i |
|
|
|
|
| sem |
|
|
|
|
sem := Semaphore new.
|
|
|
|
sem fireTime: (200 - i).
|
|
|
|
sempq insert: sem
|
|
|
|
].
|
|
|
|
|
|
|
|
'--------------------------' dump.
|
|
|
|
sempq deleteAt: 40.
|
|
|
|
sempq deleteAt: 50.
|
|
|
|
sempq deleteAt: 100.
|
|
|
|
|
|
|
|
a := -100.
|
|
|
|
[sempq size > 0] whileTrue: [
|
|
|
|
| sem b |
|
|
|
|
sem := sempq popTop.
|
|
|
|
b := sem fireTime.
|
|
|
|
if (a > b) { ^false }.
|
|
|
|
a := b.
|
|
|
|
].
|
|
|
|
|
|
|
|
^true
|
|
|
|
}
|
|
|
|
|
2017-10-02 01:22:49 +00:00
|
|
|
method(#class) test_mutex
|
|
|
|
{
|
|
|
|
| mtx sem v p q |
|
|
|
|
|
|
|
|
mtx := Mutex new.
|
|
|
|
sem := Semaphore new.
|
|
|
|
|
|
|
|
p := 0.
|
|
|
|
|
|
|
|
[ mtx lock.
|
|
|
|
v := 0.
|
|
|
|
2000 timesRepeat: [v := v + 1. p := p + 1. ].
|
|
|
|
q := v.
|
|
|
|
mtx unlock.
|
|
|
|
sem signal.
|
|
|
|
] fork.
|
|
|
|
|
|
|
|
[ mtx critical: [
|
|
|
|
v := 0.
|
|
|
|
2000 timesRepeat: [v := v + 1. p := p + 1. ].
|
|
|
|
q := v.
|
|
|
|
].
|
|
|
|
sem signal.
|
|
|
|
] fork.
|
|
|
|
|
|
|
|
mtx lock.
|
|
|
|
v := 0.
|
|
|
|
2000 timesRepeat: [v := v + 1. p := p + 1. ].
|
|
|
|
mtx unlock.
|
|
|
|
|
|
|
|
sem wait.
|
|
|
|
sem wait.
|
|
|
|
|
|
|
|
^%( v, p ) ## v must be 2000, p must be 6000
|
|
|
|
}
|
|
|
|
|
2017-10-05 17:14:38 +00:00
|
|
|
(*
|
|
|
|
method(#class) test_sem_sig
|
|
|
|
{
|
|
|
|
| s |
|
|
|
|
s := Semaphore new.
|
|
|
|
s signalAction: [:sem | 'SIGNAL ACTION............' dump. ].
|
2017-11-05 16:47:13 +00:00
|
|
|
[ System sleepForSecs: 1. s signal ] fork.
|
2017-10-05 17:14:38 +00:00
|
|
|
s wait.
|
|
|
|
}
|
|
|
|
|
|
|
|
method(#class) test_semgrp
|
|
|
|
{
|
|
|
|
| sg |
|
|
|
|
sg := SemaphoreGroup new.
|
|
|
|
sg add: s1 withAction: [].
|
|
|
|
sg add: s2 withAction: [].
|
|
|
|
sg add: s3 withAction: [].
|
|
|
|
sg wait.
|
|
|
|
}
|
|
|
|
*)
|
|
|
|
|
2017-06-07 17:22:14 +00:00
|
|
|
method(#class) main
|
2016-03-28 13:27:03 +00:00
|
|
|
{
|
2017-06-07 17:22:14 +00:00
|
|
|
| tc limit |
|
2016-03-28 13:27:03 +00:00
|
|
|
|
2017-06-16 09:45:22 +00:00
|
|
|
tc := %(
|
2017-06-08 14:39:17 +00:00
|
|
|
## 0 - 4
|
2017-06-07 17:22:14 +00:00
|
|
|
[ self proc1 == 100 ],
|
2017-11-05 16:47:13 +00:00
|
|
|
[ System sleepForSecs: 2. self proc1 == 200 ],
|
2017-10-02 01:22:49 +00:00
|
|
|
[ self test_semaphore_heap == true ],
|
2017-10-05 17:14:38 +00:00
|
|
|
[ self test_mutex = #(2000 6000) ],
|
|
|
|
####[ self test_sem_sig ],
|
|
|
|
[ a == 300 ]
|
2017-06-16 09:45:22 +00:00
|
|
|
).
|
2016-03-28 13:27:03 +00:00
|
|
|
|
2017-06-07 17:22:14 +00:00
|
|
|
limit := tc size.
|
2016-03-28 13:27:03 +00:00
|
|
|
|
2017-06-07 17:22:14 +00:00
|
|
|
0 priorTo: limit by: 1 do: [ :idx |
|
|
|
|
| tb |
|
|
|
|
tb := tc at: idx.
|
|
|
|
System log(System.Log.INFO, idx asString, (if (tb value) { ' PASS' } else { ' FAIL' }), S'\n').
|
2017-07-21 16:54:43 +00:00
|
|
|
].
|
2016-03-28 13:27:03 +00:00
|
|
|
}
|
|
|
|
}
|
2017-10-05 17:14:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
(*
|
|
|
|
s1 := TcpSocket new.
|
|
|
|
|
|
|
|
s1 onEvent: #connected do: [
|
2017-10-30 01:11:18 +00:00
|
|
|
s1 waitToRead.
|
|
|
|
##s1 beginWrite: C'GET / HTTP/1.0\n\r'.
|
2017-10-05 17:14:38 +00:00
|
|
|
]
|
|
|
|
s1 onEvent: #written do: [
|
2017-10-30 01:11:18 +00:00
|
|
|
].
|
2017-10-05 17:14:38 +00:00
|
|
|
|
2017-10-30 01:11:18 +00:00
|
|
|
s1 onEvent: #readyToRead do: [
|
|
|
|
|
|
|
|
].
|
2017-10-05 17:14:38 +00:00
|
|
|
|
2017-10-30 01:11:18 +00:00
|
|
|
s1 beginConnect: '1.2.3.4:45' onConnected: [ :result | xxxx].
|
|
|
|
|
|
|
|
|
|
|
|
####
|
|
|
|
s1 beginConnect: destination onConnected:
|
|
|
|
s1 endConnect --> return what?
|
|
|
|
s1 endReceive
|
|
|
|
s1 beginReceive: buffer callback: [xxxx].
|
|
|
|
s1 beginSend: data onEnd: [do this].
|
|
|
|
s1 endSend
|
|
|
|
|
|
|
|
s1 beginAccept: [callback]
|
|
|
|
s1 endAccept -> returns the actual socket
|
2017-10-05 17:14:38 +00:00
|
|
|
*)
|