Changeset 36250 in project


Ignore:
Timestamp:
08/13/18 05:01:55 (4 months ago)
Author:
kon
Message:

ex

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/5/mailbox

    r36211 r36250  
    3333Returns a new mailbox object.
    3434
    35 ; {{NAME}} : {{*}} ; default {{(gensym 'mailbox)}}
     35; {{NAME}} : {{*}} : default {{(gensym 'mailbox)}}
    3636
    3737* identify this mailbox.
     
    4747<procedure>(mailbox-name MAILBOX) -> *</procedure>
    4848
    49 Returns the name of the {{MAILBOX}}.
     49Returns the name of {{MAILBOX}}.
    5050
    5151=== mailbox-empty?
     
    5353<procedure>(mailbox-empty? MAILBOX) -> boolean</procedure>
    5454
    55 If there are no queued objects in the {{MAILBOX}}, then
    56 this procedure returns {{#t}}, otherwise it returns {{#f}}.
     55If there are no queued objects in {{MAILBOX}}, returns {{#t}}, otherwise
     56{{#f}}.
    5757
    5858=== mailbox-count
     
    6060<procedure>(mailbox-count MAILBOX) -> integer</procedure>
    6161
    62 Returns the number of queued objects for the {{MAILBOX}}.
     62Returns the number of queued objects for {{MAILBOX}}.
    6363
    6464=== mailbox-waiting?
     
    6666<procedure>(mailbox-waiting? MAILBOX) -> boolean</procedure>
    6767
    68 Is any thread waiting for the {{MAILBOX}}?
     68Is a thread waiting for {{MAILBOX}}?
    6969
    7070=== mailbox-waiters
    7171
    72 <procedure>(mailbox-waiters MAILBOX) -> list</procedure>
    73 
    74 Returns a list of the threads waiting for the {{MAILBOX}}.
     72<procedure>(mailbox-waiters MAILBOX) -> (list-of thread)</procedure>
     73
     74Returns the threads waiting for {{MAILBOX}}.
    7575
    7676=== mailbox-send!
     
    8787<procedure>(mailbox-receive! MAILBOX [TIMEOUT [DEFAULT]]) -> *</procedure>
    8888
    89 If there is any data in the {{MAILBOX}}, then the first object will be
     89If there is any data in {{MAILBOX}}, then the first object will be
    9090removed and returned as the result. If the mailbox is currently empty,
    9191the current thread will suspended until data is available.
     
    180180<procedure>(mailbox-cursor-rewound? MAILBOX-CURSOR) -> boolean</procedure>
    181181
    182 Is the {{MAILBOX-CURSOR}} positioned at the start of the mailbox queue?
     182Is {{MAILBOX-CURSOR}} positioned at the start of the mailbox queue?
    183183
    184184=== mailbox-cursor-unwound?
     
    186186<procedure>(mailbox-cursor-unwound? MAILBOX-CURSOR) -> boolean</procedure>
    187187
    188 Is the {{MAILBOX-CURSOR}} positioned at the end of the mailbox queue?
     188Is {{MAILBOX-CURSOR}} positioned at the end of the mailbox queue?
    189189
    190190
     
    199199
    200200<enscript language=scheme>
    201 (import (srfi 18) mailbox)
     201(import (chicken base) (srfi 18) mailbox)
    202202
    203203(define (say dir msg)
     
    205205
    206206(define (producer ch x)
    207   (say "writing" x)
    208   (mailbox-send! ch x) )
     207  (make-thread
     208    (lambda ()
     209      (say "writing" x)
     210      (mailbox-send! ch x) ) ) )
    209211
    210212(define (consumer ch)
     
    218220(define ch (make-mailbox))
    219221(define t (thread-start! (consumer ch)))
    220 (for-each (cut producer ch <>) '(ready set go quit))
     222(for-each (lambda (x) (thread-join! (thread-start! (producer ch x)))) '(ready set go quit))
    221223(thread-join! t)
    222224</enscript>
     
    229231timeout value when the {{(current-thread)}} is the {{##sys#primordial-thread}}.
    230232
    231 * A ''deadlock'' is possible when using {{mailbox-wait!}},
    232 {{mailbox-receive!}}, or {{mailbox-cursor-next}} should there be no other
    233 threads ''runnable''.
    234 
    235 When a mailbox is empty the {{(current-thread)}} is suspended (indefinite
    236 block). Then the scheduler looks for the next ready thread. If one is not
    237 available it signals ''deadlock''. Using a {{TIMEOUT}} will allow the calling
    238 thread to unblock eventually.
     233* A '''deadlock''' is possible when using {{mailbox-wait!}},
     234{{mailbox-receive!}}, or {{mailbox-cursor-next}}, should there be no other
     235threads ''runnable''. When a mailbox is empty the {{(current-thread)}} is
     236suspended (indefinite block). Then the scheduler looks for the next ready
     237thread. If one is not available it signals ''deadlock''. Using a {{TIMEOUT}}
     238will allow the calling thread to unblock eventually.
    239239
    240240* A {{mailbox-cursor}} must live in an environment where {{mailbox}} entries
     
    245245
    246246[[/users/felix winkelmann|felix winkelmann]]
    247 
    248247[[/users/kon lovett|Kon Lovett]]
    249248
Note: See TracChangeset for help on using the changeset viewer.