Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
33
Task/Synchronous-concurrency/TXR/synchronous-concurrency.txr
Normal file
33
Task/Synchronous-concurrency/TXR/synchronous-concurrency.txr
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
(defstruct thread nil
|
||||
suspended
|
||||
cont
|
||||
(:method resume (self)
|
||||
[self.cont])
|
||||
(:method give (self item)
|
||||
[self.cont item])
|
||||
(:method get (self)
|
||||
(yield-from run nil))
|
||||
(:method start (self)
|
||||
(set self.cont (obtain self.(run)))
|
||||
(unless self.suspended
|
||||
self.(resume)))
|
||||
(:postinit (self)
|
||||
self.(start)))
|
||||
|
||||
(defstruct consumer thread
|
||||
(count 0)
|
||||
(:method run (self)
|
||||
(whilet ((item self.(get)))
|
||||
(prinl item)
|
||||
(inc self.count))))
|
||||
|
||||
(defstruct producer thread
|
||||
consumer
|
||||
(:method run (self)
|
||||
(whilet ((line (get-line)))
|
||||
self.consumer.(give line))))
|
||||
|
||||
(let* ((con (new consumer))
|
||||
(pro (new producer suspended t consumer con)))
|
||||
pro.(resume)
|
||||
(put-line `count = @{con.count}`))
|
||||
Loading…
Add table
Add a link
Reference in a new issue