I/O, sleeps, or otherwise causes a thread switch. Presumably such a
procedure has some other way of enforcing the LIFO ordering.
-The @code{outf-console} procedure is provided for debugging purposes.
+The @code{outf-error} procedure is provided for debugging purposes.
It writes one or more argument strings (and @code{write}s any
-non-strings) to the console and flushes, atomically, via a machine
+non-strings) to the Unix ``stderr'' channel, atomically, via a machine
primitive, bypassing the runtime's I/O buffering and thread switching.
-Thus multiple debugging trace messages arrive on the console intact
+Thus trace messages from multiple threads will appear on stderr intact
and uninterrupted.
-
@node Compiling and Linking, Hello World, Callbacks, Top
@chapter Compiling and Linking
(C-callback "delete_event") ;trampoline
(C-callback ;callback ID
(lambda (w e)
- (outf-console ";Delete me "(- 2 counter)" times.\n")
+ (outf-error ";Delete me "(- 2 counter)" times.\n")
(set! counter (1+ counter))
;; Three or more is the charm.
(if (> counter 2)
(define-syntax %trace
(syntax-rules ()
- ((_ . ARGS) (if %trace? ((lambda () (outf-console . ARGS)))))))
+ ((_ . ARGS) (if %trace? ((lambda () (outf-error . ARGS)))))))
(define-syntax %trace2
(syntax-rules ()
- ((_ . ARGS) (if %trace2? ((lambda () (outf-console . ARGS)))))))
\ No newline at end of file
+ ((_ . ARGS) (if %trace2? ((lambda () (outf-error . ARGS)))))))
\ No newline at end of file
(define-syntax %trace
(syntax-rules ()
- ((_ . ARGS) (if %trace? ((lambda () (outf-console . ARGS)))))))
+ ((_ . ARGS) (if %trace? ((lambda () (outf-error . ARGS)))))))
(define %trace2? #f)
(define-syntax %trace2
(syntax-rules ()
- ((_ . ARGS) (if %trace2? ((lambda () (outf-console . ARGS)))))))
\ No newline at end of file
+ ((_ . ARGS) (if %trace2? ((lambda () (outf-error . ARGS)))))))
\ No newline at end of file
(define-syntax %trace
(syntax-rules ()
- ((_ . ARGS) (if %trace? ((lambda () (outf-console . ARGS)))))))
\ No newline at end of file
+ ((_ . ARGS) (if %trace? ((lambda () (outf-error . ARGS)))))))
\ No newline at end of file
(define-syntax %trace
(syntax-rules ()
- ((_ . ARGS) (if %trace? ((lambda () (outf-console . ARGS)))))))
+ ((_ . ARGS) (if %trace? ((lambda () (outf-error . ARGS)))))))
(initialize-package!)
\ No newline at end of file
(define-syntax %trace
(syntax-rules ()
- ((_ . ARGS) (if %trace? ((lambda () (outf-console . ARGS)))))))
+ ((_ . ARGS) (if %trace? ((lambda () (outf-error . ARGS)))))))
(define %trace2? #f)
(define-syntax %trace2
(syntax-rules ()
- ((_ . ARGS) (if %trace2? ((lambda () (outf-console . ARGS)))))))
\ No newline at end of file
+ ((_ . ARGS) (if %trace2? ((lambda () (outf-error . ARGS)))))))
\ No newline at end of file
(define-syntax %trace
(syntax-rules ()
- ((_ . ARGS) (if %trace? ((lambda () (outf-console . ARGS)))))))
\ No newline at end of file
+ ((_ . ARGS) (if %trace? ((lambda () (outf-error . ARGS)))))))
\ No newline at end of file
(set-gtk-window-delete-event-callback!
window
(lambda (window)
- (outf-console ";Bite me "(- 2 counter)" times.\n")
+ (outf-error ";Bite me "(- 2 counter)" times.\n")
(set! counter (1+ counter))
;; Three or more is the charm.
(if (> counter 2) 0 1)))
(define-syntax %trace
(syntax-rules ()
- ((_ . ARGS) (if %trace? ((lambda () (outf-console . ARGS)))))))
+ ((_ . ARGS) (if %trace? ((lambda () (outf-error . ARGS)))))))
(define %trace2? #f)
(define-syntax %trace2
(syntax-rules ()
- ((_ . ARGS) (if %trace2? ((lambda () (outf-console . ARGS)))))))
+ ((_ . ARGS) (if %trace2? ((lambda () (outf-error . ARGS)))))))
(initialize-package!)
\ No newline at end of file
(define-syntax %trace
(syntax-rules ()
((_ . MSG)
- (if %trace? ((lambda () (outf-console . MSG)))))))
\ No newline at end of file
+ (if %trace? ((lambda () (outf-error . MSG)))))))
\ No newline at end of file
return (EMPTY_LIST);
}
-DEFINE_PRIMITIVE ("OUTF-CONSOLE", Prim_outf_console, 1, 1, 0)
+DEFINE_PRIMITIVE ("OUTF-ERROR", Prim_outf_error, 1, 1, 0)
{
- /* To avoid the normal i/o system when debugging a callback. */
+ /* To avoid the normal i/o system when debugging a callback. Uses
+ the Unix "stderr" channel. */
PRIMITIVE_HEADER (1);
{
if (STRING_P (arg))
{
char * string = ((char *) STRING_LOC (arg, 0));
- outf_console ("%s", string);
- outf_flush_console ();
+ outf_error ("%s", string);
+ outf_flush_error ();
}
else
{
(define (call-alien* alien-function args)
(let ((old-top calloutback-stack))
(%if-tracing
- (outf-console ";"(tindent)"=> "alien-function" "args"\n")
+ (outf-error ";"(tindent)"=> "alien-function" "args"\n")
(set! calloutback-stack (cons (cons* alien-function args) old-top)))
(let ((value (apply (ucode-primitive c-call -1) alien-function args)))
(%if-tracing
(%assert (eq? old-top (cdr calloutback-stack))
"call-alien: freak stack "calloutback-stack"\n")
(set! calloutback-stack old-top)
- (outf-console ";"(tindent)"<= "value"\n"))
+ (outf-error ";"(tindent)"<= "value"\n"))
value)))
\f
(normalize-aliens! args)
(let ((old-top calloutback-stack))
(%if-tracing
- (outf-console ";"(tindent)"=>> "procedure" "args"\n")
+ (outf-error ";"(tindent)"=>> "procedure" "args"\n")
(set! calloutback-stack (cons (cons procedure args) old-top)))
(let ((value (apply-callback-proc procedure args)))
(%if-tracing
(eq? old-top (cdr calloutback-stack)))
"callback-handler: freak stack "calloutback-stack"\n")
(set! calloutback-stack old-top)
- (outf-console ";"(tindent)"<<= "value"\n"))
+ (outf-error ";"(tindent)"<<= "value"\n"))
value))))
(define (apply-callback-proc procedure args)
;;; For callback debugging:
-(define (outf-console . objects)
- ((ucode-primitive outf-console 1)
+(define (outf-error . objects)
+ ((ucode-primitive outf-error 1)
(apply string-append
(map (lambda (o) (if (string? o) o (write-to-string o)))
objects))))
(define-syntax %trace
(syntax-rules ()
((_ . MSG)
- (if %trace? ((lambda () (outf-console . MSG)))))))
+ (if %trace? ((lambda () (outf-error . MSG)))))))
(define (tindent)
(make-string (* 2 (length calloutback-stack)) #\space))
\ No newline at end of file
free
register-c-callback
de-register-c-callback
- outf-console)
+ outf-error)
(initialization (initialize-package!)))
(define-package (runtime program-copier)
;; Sets up a "producer" thread that puts the letters of the alphabet
;; into a thread-queue, one each 2-3 seconds. A "consumer" thread
;; waits on the queue, printing what it reads.
- (outf-console ";Thread Queue Test\n")
+ (outf-error ";Thread Queue Test\n")
(let ((queue (make-thread-queue)))
(create-thread
#f
(lambda ()
- (outf-console "; Consumer: "(current-thread)"\n")
+ (outf-error "; Consumer: "(current-thread)"\n")
(let loop ()
- (outf-console "; Consumer reads.\n")
+ (outf-error "; Consumer reads.\n")
(let ((item (thread-queue/dequeue! queue)))
- (outf-console "; Consumer read "item"\n")
+ (outf-error "; Consumer read "item"\n")
(loop)))))
(create-thread
#f
(lambda ()
- (outf-console "; Producer: "(current-thread)"\n")
+ (outf-error "; Producer: "(current-thread)"\n")
(for-each (lambda (item)
- (outf-console "; Producer: sleeping...\n")
+ (outf-error "; Producer: sleeping...\n")
(sleep-current-thread 2000)
- (outf-console "; Producer: queuing "item"...\n")
+ (outf-error "; Producer: queuing "item"...\n")
(thread-queue/queue! queue item)
- (outf-console "; Producer: queued "item"\n"))
+ (outf-error "; Producer: queued "item"\n"))
'(#\a #\b #\c #\d #\e))
- (outf-console "; Producer done.\n")))))
\ No newline at end of file
+ (outf-error "; Producer done.\n")))))
\ No newline at end of file
(define-syntax %trace
(syntax-rules ()
((_ . MSG)
- (if %trace? ((lambda () (outf-console . MSG)))))))
+ (if %trace? ((lambda () (outf-error . MSG)))))))
(define (yield-current-thread)
(without-interrupts