<commit_before>;; -*- lisp -*-

;; This file is part of STMX.
;; Copyright (c) 2013 <NAME>
;;
;; This library is free software: you can redistribute it and/or
;; modify it under the terms of the Lisp Lesser General Public License
;; (http://opensource.franz.com/preamble.html), known as the LLGPL.
;;
;; This library is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty
;; of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;; See the Lisp Lesser General Public License for more details.


(in-package :stmx.lang)


;;;; * Wrappers around Bordeaux Threads to capture the values returned by functions executed in threads

#-sane-bt-join-thread
(defstruct wrapped-thread
  (result nil)
  (thread (current-thread) :type thread))


#-sane-bt-join-thread
(defstruct wrapped-thread
  (result nil)
  (thread (current-thread) :type thread))

(defun start-thread (function &key name (initial-bindings bt:*default-special-bindings*))

  #+sane-bt-join-thread
  (make-thread function name initial-bindings)

  #-sane-bt-join-thread
  (let1 th (make-wrapped-thread)
    (setf (wrapped-thread-thread th)
          (make-thread (lambda ()
                         (setf (wrapped-thread-result th)
                               (funcall function)))
                       :name name
                       :initial-bindings initial-bindings))
    th))

#-sane-bt-join-thread
(defun wait4-thread (th)
  (declare (type wrapped-thread th))

  (join-thread (wrapped-thread-thread th))
  (wrapped-thread-result th))


#+sane-bt-join-thread
(defun wait4-thread (th)
  (declare (type thread th))
  (join-thread th))
<commit_msg>bugfix in lang/thread.lisp: removed duplicate (defstruct wrapped-thread ...), fixed call to (bordeaux-threads:make-thread ...)<commit_after>;; -*- lisp -*-

;; This file is part of STMX.
;; Copyright (c) 2013 <NAME>
;;
;; This library is free software: you can redistribute it and/or
;; modify it under the terms of the Lisp Lesser General Public License
;; (http://opensource.franz.com/preamble.html), known as the LLGPL.
;;
;; This library is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty
;; of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;; See the Lisp Lesser General Public License for more details.


(in-package :stmx.lang)


;;;; * Wrappers around Bordeaux Threads to capture the values returned by functions executed in threads

#-stmx-sane-bt.join-thread
(defstruct wrapped-thread
  (result nil)
  (thread (current-thread) :type thread))


(defun start-thread (function &key name (initial-bindings bt:*default-special-bindings*))

  #+stmx-sane-bt.join-thread
  (make-thread function :name name :initial-bindings initial-bindings)

  #-stmx-sane-bt.join-thread
  (let1 th (make-wrapped-thread)
    (setf (wrapped-thread-thread th)
          (make-thread (lambda ()
                         (setf (wrapped-thread-result th)
                               (funcall function)))
                       :name name
                       :initial-bindings initial-bindings))
    th))

#-stmx-sane-bt.join-thread
(defun wait4-thread (th)
  (declare (type wrapped-thread th))

  (join-thread (wrapped-thread-thread th))
  (wrapped-thread-result th))


#+stmx-sane-bt.join-thread
(defun wait4-thread (th)
  (declare (type thread th))
  (join-thread th))

{'fraction_non_alphanumeric': 0.11992945326278659, 'fraction_numerical': 0.00411522633744856, 'mean_word_length': 3.090144230769231, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3899510', 'n_tokens_mistral': 1055, 'n_tokens_neox': 1021, 'n_words': 336}