(declare (block) (standard-bindings) (extended-bindings))
(begin
  (define gerbil/gambit/threads#spawn
    (lambda (_f64602_ . _args64603_)
      (gerbil/gambit/threads#spawn-actor _f64602_ _args64603_ '#!void '#f)))
  (define gerbil/gambit/threads#spawn/name
    (lambda (_name64598_ _f64599_ . _args64600_)
      (gerbil/gambit/threads#spawn-actor
       _f64599_
       _args64600_
       _name64598_
       '#f)))
  (define gerbil/gambit/threads#spawn/group
    (lambda (_name64592_ _f64593_ . _args64594_)
      (let ((_tgroup64596_ (make-thread-group _name64592_)))
        (gerbil/gambit/threads#spawn-actor
         _f64593_
         _args64594_
         _name64592_
         _tgroup64596_))))
  (define gerbil/gambit/threads#spawn-actor
    (lambda (_f64570_ _args64571_ _name64572_ _tgroup64573_)
      (letrec ((_thread-main64575_
                (lambda (_thunk64584_)
                  (lambda ()
                    (with-exception-handler
                     (lambda (_exn64587_)
                       (##continuation-capture
                        (lambda (_cont64589_)
                          (if gerbil/gambit/threads#unhandled-actor-exception-hook
                              (with-exception-catcher
                               void
                               (lambda ()
                                 (gerbil/gambit/threads#unhandled-actor-exception-hook
                                  _cont64589_
                                  _exn64587_)))
                              '#!void)
                          (##continuation-graft
                           (##continuation-last _cont64589_)
                           ##primordial-exception-handler
                           _exn64587_))))
                     _thunk64584_)))))
        (if (procedure? _f64570_)
            (let ((_thunk64581_
                   (if (null? _args64571_)
                       _f64570_
                       (lambda () (apply _f64570_ _args64571_))))
                  (_tgroup64582_
                   (let ((_$e64578_ _tgroup64573_))
                     (if _$e64578_
                         _$e64578_
                         (gerbil/gambit/threads#current-thread-group)))))
              (thread-start!
               (thread-init!
                (gerbil/gambit/threads#construct-actor-thread '#f)
                (_thread-main64575_ _thunk64581_)
                _name64572_
                _tgroup64582_)))
            (error '"Bad argument; expected procedure" _f64570_)))))
  (namespace
   ("gerbil/gambit/threads#"
    construct-actor-thread
    actor-thread?
    actor-thread-locals
    actor-thread-locals-set!))
  (define-type-of-thread
   actor-thread
   constructor:
   construct-actor-thread
   id:
   gerbil#actor-thread::t
   locals)
  (define gerbil/gambit/threads#spawn-thread__%
    (lambda (_thunk64548_ _name64549_ _tgroup64550_)
      (thread-start! (make-thread _thunk64548_ _name64549_ _tgroup64550_))))
  (define gerbil/gambit/threads#spawn-thread__0
    (lambda (_thunk64555_)
      (let* ((_name64557_ absent-obj) (_tgroup64559_ absent-obj))
        (gerbil/gambit/threads#spawn-thread__%
         _thunk64555_
         _name64557_
         _tgroup64559_))))
  (define gerbil/gambit/threads#spawn-thread__1
    (lambda (_thunk64561_ _name64562_)
      (let ((_tgroup64564_ absent-obj))
        (gerbil/gambit/threads#spawn-thread__%
         _thunk64561_
         _name64562_
         _tgroup64564_))))
  (define gerbil/gambit/threads#spawn-thread
    (lambda _g64605_
      (let ((_g64604_ (length _g64605_)))
        (cond ((##fx= _g64604_ 1)
               (apply gerbil/gambit/threads#spawn-thread__0 _g64605_))
              ((##fx= _g64604_ 2)
               (apply gerbil/gambit/threads#spawn-thread__1 _g64605_))
              ((##fx= _g64604_ 3)
               (apply gerbil/gambit/threads#spawn-thread__% _g64605_))
              (else
               (##raise-wrong-number-of-arguments-exception
                gerbil/gambit/threads#spawn-thread
                _g64605_))))))
  (define gerbil/gambit/threads#thread-local-ref__%
    (lambda (_key64532_ _default64533_)
      (let ((_tab64535_ (gerbil/gambit/threads#thread-local-table)))
        (table-ref _tab64535_ _key64532_ _default64533_))))
  (define gerbil/gambit/threads#thread-local-ref__0
    (lambda (_key64540_)
      (let ((_default64542_ absent-obj))
        (gerbil/gambit/threads#thread-local-ref__%
         _key64540_
         _default64542_))))
  (define gerbil/gambit/threads#thread-local-ref
    (lambda _g64607_
      (let ((_g64606_ (length _g64607_)))
        (cond ((##fx= _g64606_ 1)
               (apply gerbil/gambit/threads#thread-local-ref__0 _g64607_))
              ((##fx= _g64606_ 2)
               (apply gerbil/gambit/threads#thread-local-ref__% _g64607_))
              (else
               (##raise-wrong-number-of-arguments-exception
                gerbil/gambit/threads#thread-local-ref
                _g64607_))))))
  (define gerbil/gambit/threads#thread-local-get
    (lambda (_key64529_)
      (gerbil/gambit/threads#thread-local-ref__% _key64529_ '#f)))
  (define gerbil/gambit/threads#thread-local-set!
    (lambda (_key64524_ _value64525_)
      (let ((_tab64527_ (gerbil/gambit/threads#thread-local-table)))
        (table-set! _tab64527_ _key64524_ _value64525_))))
  (define gerbil/gambit/threads#thread-local-clear!
    (lambda (_key64520_)
      (let ((_tab64522_ (gerbil/gambit/threads#thread-local-table)))
        (table-set! _tab64522_ _key64520_))))
  (define gerbil/gambit/threads#thread-local-table
    (lambda ()
      (let ((_thr64506_ (current-thread)))
        (if (gerbil/gambit/threads#actor-thread? _thr64506_)
            (let ((_$e64508_
                   (gerbil/gambit/threads#actor-thread-locals _thr64506_)))
              (if _$e64508_
                  (values _$e64508_)
                  (let ((_tab64511_ (make-table 'test: eq?)))
                    (gerbil/gambit/threads#actor-thread-locals-set!
                     _thr64506_
                     _tab64511_)
                    _tab64511_)))
            (if (eq? _thr64506_ ##primordial-thread)
                gerbil/gambit/threads#*primordial-thread-locals*
                (begin
                  (mutex-lock! gerbil/gambit/threads#*thread-locals-mutex*)
                  (let ((_$e64513_
                         (table-ref
                          gerbil/gambit/threads#*thread-locals*
                          _thr64506_
                          '#f)))
                    (if _$e64513_
                        ((lambda (_tab64516_)
                           (mutex-unlock!
                            gerbil/gambit/threads#*thread-locals-mutex*)
                           _tab64516_)
                         _$e64513_)
                        (let ((_tab64518_ (make-table 'test: eq?)))
                          (table-set!
                           gerbil/gambit/threads#*thread-locals*
                           _thr64506_
                           _tab64518_)
                          (mutex-unlock!
                           gerbil/gambit/threads#*thread-locals-mutex*)
                          _tab64518_)))))))))
  (define gerbil/gambit/threads#*primordial-thread-locals*
    (make-table 'test: eq?))
  (define gerbil/gambit/threads#*thread-locals*
    (make-table 'test: eq? 'weak-keys: '#t))
  (define gerbil/gambit/threads#*thread-locals-mutex*
    (make-mutex 'thread-locals))
  (define gerbil/gambit/threads#unhandled-actor-exception-hook '#f)
  (define gerbil/gambit/threads#unhandled-actor-exception-hook-set!
    (lambda (_proc64500_)
      (if (or (not _proc64500_) (procedure? _proc64500_))
          (set! gerbil/gambit/threads#unhandled-actor-exception-hook
                _proc64500_)
          (error '"Bad argument; expected procedure or #f" _proc64500_))))
  (define gerbil/gambit/threads#with-exception-stack-trace__%
    (lambda (_thunk64481_ _error-port64482_)
      (with-exception-handler
       (let ((_E64484_ (current-exception-handler)))
         (lambda (_exn64486_)
           (##continuation-capture
            (lambda (_cont64488_)
              (gerbil/gambit/threads#dump-stack-trace!
               _cont64488_
               _exn64486_
               _error-port64482_)
              (_E64484_ _exn64486_)))))
       _thunk64481_)))
  (define gerbil/gambit/threads#with-exception-stack-trace__0
    (lambda (_thunk64493_)
      (let ((_error-port64495_ (current-error-port)))
        (gerbil/gambit/threads#with-exception-stack-trace__%
         _thunk64493_
         _error-port64495_))))
  (define gerbil/gambit/threads#with-exception-stack-trace
    (lambda _g64609_
      (let ((_g64608_ (length _g64609_)))
        (cond ((##fx= _g64608_ 1)
               (apply gerbil/gambit/threads#with-exception-stack-trace__0
                      _g64609_))
              ((##fx= _g64608_ 2)
               (apply gerbil/gambit/threads#with-exception-stack-trace__%
                      _g64609_))
              (else
               (##raise-wrong-number-of-arguments-exception
                gerbil/gambit/threads#with-exception-stack-trace
                _g64609_))))))
  (namespace ("gerbil/gambit/threads#" dump-stack-trace!))
  (define (dump-stack-trace!
           cont
           exn
           #!optional
           (error-port (current-error-port)))
    (let ((out (open-output-string)))
      (display "*** Unhandled exception in " out)
      (display (current-thread) out)
      (newline out)
      (display-exception exn out)
      (display "Continuation backtrace: " out)
      (newline out)
      (##display-continuation-backtrace
       cont
       out
       #f
       #f
       ##backtrace-default-max-head
       ##backtrace-default-max-tail
       0)
      (##write-string (get-output-string out) error-port)))
  (define gerbil/gambit/threads#current-thread-group
    (lambda () (thread-thread-group (current-thread))))
  (define gerbil/gambit/threads#with-lock
    (lambda (_mx64474_ _proc64475_)
      (dynamic-wind
       (lambda () (mutex-lock! _mx64474_))
       _proc64475_
       (lambda () (mutex-unlock! _mx64474_))))))
