(declare (block) (standard-bindings) (extended-bindings))
(begin
  (define gerbil/gambit/threads#spawn
    (lambda (_f65783_ . _args65784_)
      (gerbil/gambit/threads#spawn-actor _f65783_ _args65784_ '#!void '#f)))
  (define gerbil/gambit/threads#spawn/name
    (lambda (_name65779_ _f65780_ . _args65781_)
      (gerbil/gambit/threads#spawn-actor
       _f65780_
       _args65781_
       _name65779_
       '#f)))
  (define gerbil/gambit/threads#spawn/group
    (lambda (_name65773_ _f65774_ . _args65775_)
      (let ((_tgroup65777_ (make-thread-group _name65773_)))
        (gerbil/gambit/threads#spawn-actor
         _f65774_
         _args65775_
         _name65773_
         _tgroup65777_))))
  (define gerbil/gambit/threads#spawn-actor
    (lambda (_f65751_ _args65752_ _name65753_ _tgroup65754_)
      (letrec ((_thread-main65756_
                (lambda (_thunk65765_)
                  (lambda ()
                    (with-exception-handler
                     (lambda (_exn65768_)
                       (##continuation-capture
                        (lambda (_cont65770_)
                          (if gerbil/gambit/threads#unhandled-actor-exception-hook
                              (with-exception-catcher
                               void
                               (lambda ()
                                 (gerbil/gambit/threads#unhandled-actor-exception-hook
                                  _cont65770_
                                  _exn65768_)))
                              '#!void)
                          (##continuation-graft
                           (##continuation-last _cont65770_)
                           ##primordial-exception-handler
                           _exn65768_))))
                     _thunk65765_)))))
        (if (procedure? _f65751_)
            (let ((_thunk65762_
                   (if (null? _args65752_)
                       _f65751_
                       (lambda () (apply _f65751_ _args65752_))))
                  (_tgroup65763_
                   (let ((_$e65759_ _tgroup65754_))
                     (if _$e65759_
                         _$e65759_
                         (gerbil/gambit/threads#current-thread-group)))))
              (thread-start!
               (thread-init!
                (gerbil/gambit/threads#construct-actor-thread '#f)
                (_thread-main65756_ _thunk65762_)
                _name65753_
                _tgroup65763_)))
            (error '"Bad argument; expected procedure" _f65751_)))))
  (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 (_thunk65729_ _name65730_ _tgroup65731_)
      (thread-start! (make-thread _thunk65729_ _name65730_ _tgroup65731_))))
  (define gerbil/gambit/threads#spawn-thread__0
    (lambda (_thunk65736_)
      (let* ((_name65738_ absent-obj) (_tgroup65740_ absent-obj))
        (gerbil/gambit/threads#spawn-thread__%
         _thunk65736_
         _name65738_
         _tgroup65740_))))
  (define gerbil/gambit/threads#spawn-thread__1
    (lambda (_thunk65742_ _name65743_)
      (let ((_tgroup65745_ absent-obj))
        (gerbil/gambit/threads#spawn-thread__%
         _thunk65742_
         _name65743_
         _tgroup65745_))))
  (define gerbil/gambit/threads#spawn-thread
    (lambda _g65786_
      (let ((_g65785_ (length _g65786_)))
        (cond ((##fx= _g65785_ 1)
               (apply gerbil/gambit/threads#spawn-thread__0 _g65786_))
              ((##fx= _g65785_ 2)
               (apply gerbil/gambit/threads#spawn-thread__1 _g65786_))
              ((##fx= _g65785_ 3)
               (apply gerbil/gambit/threads#spawn-thread__% _g65786_))
              (else
               (##raise-wrong-number-of-arguments-exception
                gerbil/gambit/threads#spawn-thread
                _g65786_))))))
  (define gerbil/gambit/threads#thread-local-ref__%
    (lambda (_key65713_ _default65714_)
      (let ((_tab65716_ (gerbil/gambit/threads#thread-local-table)))
        (table-ref _tab65716_ _key65713_ _default65714_))))
  (define gerbil/gambit/threads#thread-local-ref__0
    (lambda (_key65721_)
      (let ((_default65723_ absent-obj))
        (gerbil/gambit/threads#thread-local-ref__%
         _key65721_
         _default65723_))))
  (define gerbil/gambit/threads#thread-local-ref
    (lambda _g65788_
      (let ((_g65787_ (length _g65788_)))
        (cond ((##fx= _g65787_ 1)
               (apply gerbil/gambit/threads#thread-local-ref__0 _g65788_))
              ((##fx= _g65787_ 2)
               (apply gerbil/gambit/threads#thread-local-ref__% _g65788_))
              (else
               (##raise-wrong-number-of-arguments-exception
                gerbil/gambit/threads#thread-local-ref
                _g65788_))))))
  (define gerbil/gambit/threads#thread-local-get
    (lambda (_key65710_)
      (gerbil/gambit/threads#thread-local-ref__% _key65710_ '#f)))
  (define gerbil/gambit/threads#thread-local-set!
    (lambda (_key65705_ _value65706_)
      (let ((_tab65708_ (gerbil/gambit/threads#thread-local-table)))
        (table-set! _tab65708_ _key65705_ _value65706_))))
  (define gerbil/gambit/threads#thread-local-clear!
    (lambda (_key65701_)
      (let ((_tab65703_ (gerbil/gambit/threads#thread-local-table)))
        (table-set! _tab65703_ _key65701_))))
  (define gerbil/gambit/threads#thread-local-table
    (lambda ()
      (let ((_thr65687_ (current-thread)))
        (if (gerbil/gambit/threads#actor-thread? _thr65687_)
            (let ((_$e65689_
                   (gerbil/gambit/threads#actor-thread-locals _thr65687_)))
              (if _$e65689_
                  (values _$e65689_)
                  (let ((_tab65692_ (make-table 'test: eq?)))
                    (gerbil/gambit/threads#actor-thread-locals-set!
                     _thr65687_
                     _tab65692_)
                    _tab65692_)))
            (if (eq? _thr65687_ ##primordial-thread)
                gerbil/gambit/threads#*primordial-thread-locals*
                (begin
                  (mutex-lock! gerbil/gambit/threads#*thread-locals-mutex*)
                  (let ((_$e65694_
                         (table-ref
                          gerbil/gambit/threads#*thread-locals*
                          _thr65687_
                          '#f)))
                    (if _$e65694_
                        ((lambda (_tab65697_)
                           (mutex-unlock!
                            gerbil/gambit/threads#*thread-locals-mutex*)
                           _tab65697_)
                         _$e65694_)
                        (let ((_tab65699_ (make-table 'test: eq?)))
                          (table-set!
                           gerbil/gambit/threads#*thread-locals*
                           _thr65687_
                           _tab65699_)
                          (mutex-unlock!
                           gerbil/gambit/threads#*thread-locals-mutex*)
                          _tab65699_)))))))))
  (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 (_proc65681_)
      (if (or (not _proc65681_) (procedure? _proc65681_))
          (set! gerbil/gambit/threads#unhandled-actor-exception-hook
                _proc65681_)
          (error '"Bad argument; expected procedure or #f" _proc65681_))))
  (define gerbil/gambit/threads#with-exception-stack-trace__%
    (lambda (_thunk65662_ _error-port65663_)
      (with-exception-handler
       (let ((_E65665_ (current-exception-handler)))
         (lambda (_exn65667_)
           (##continuation-capture
            (lambda (_cont65669_)
              (gerbil/gambit/threads#dump-stack-trace!
               _cont65669_
               _exn65667_
               _error-port65663_)
              (_E65665_ _exn65667_)))))
       _thunk65662_)))
  (define gerbil/gambit/threads#with-exception-stack-trace__0
    (lambda (_thunk65674_)
      (let ((_error-port65676_ (current-error-port)))
        (gerbil/gambit/threads#with-exception-stack-trace__%
         _thunk65674_
         _error-port65676_))))
  (define gerbil/gambit/threads#with-exception-stack-trace
    (lambda _g65790_
      (let ((_g65789_ (length _g65790_)))
        (cond ((##fx= _g65789_ 1)
               (apply gerbil/gambit/threads#with-exception-stack-trace__0
                      _g65790_))
              ((##fx= _g65789_ 2)
               (apply gerbil/gambit/threads#with-exception-stack-trace__%
                      _g65790_))
              (else
               (##raise-wrong-number-of-arguments-exception
                gerbil/gambit/threads#with-exception-stack-trace
                _g65790_))))))
  (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 (_mx65655_ _proc65656_)
      (dynamic-wind
       (lambda () (mutex-lock! _mx65655_))
       _proc65656_
       (lambda () (mutex-unlock! _mx65655_))))))
