google / lisp-koans

Common Lisp Koans is a language learning exercise in the same vein as the ruby koans, python koans and others. It is a port of the prior koans with some modifications to highlight lisp-specific features. Structured as ordered groups of broken unit tests, the project guides the learner progressively through many Common Lisp language features.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Thread koans: possible replacement for SEMAPHORE-COUNT

phoe opened this issue · comments

Forked from Clozure/ccl#308

Arguably it's not very informative, the count could change immediately after or
before retrieved and and since it's a condition variable you have no great
use of it for a CAS utility...

@Slids It does make sense. Were the koans doing The Right Thing™, then, utilizing a semaphore-count function that is effectively useless in real-life scenarios? Or was this function good if used only for illustrative purposes?

Nope, purely illustrative.

I've posted sionescu/bordeaux-threads#70 - let's see how it goes.

Just to not the code alluded to is:

(defun signal-semaphore (semaphore)
(bordeaux-threads:signal-semaphore
(semaphore-semaphore semaphore))
(incf (semaphore-count semaphore)))

(defun wait-on-semaphore (semaphore)
(bordeaux-threads:wait-on-semaphore
(semaphore-semaphore semaphore))
(decf (semaphore-count semaphore)))

(defun semaphore-name (semaphore)
(semaphore-name (semaphore-semaphore semaphore)))

;; Incrementing a bordeaux-threads semaphore is an atomic operation
;; but our increment is not.
(defvar g-semaphore (make-our-semaphore :name "g" :count 0))

(defun semaphore-increments-g ()
(signal-semaphore g-semaphore))

(define-test test-increment-semaphore
(assert-equal ___ (semaphore-count g-semaphore))
(bordeaux-threads:join-thread (bordeaux-threads:make-thread 'semaphore-increments-g :name "S incrementor 1"))
(bordeaux-threads:join-thread (bordeaux-threads:make-thread 'semaphore-increments-g :name "S incrementor 2"))
(bordeaux-threads:join-thread (bordeaux-threads:make-thread 'semaphore-increments-g :name "S incrementor 3"))
(assert-equal ___ (semaphore-count g-semaphore)))

It's probably useful to find a semaphore count for purely testing the semaphore code,
but not for anyone else, so no great reason to export such a function.
It also bugs me I see no testing for threads in CCL

It also bugs me I see no testing for threads in CCL

What do you mean, testing? You mean no tests for threads in CCL the implementation? I cannot see them in https://github.com/Clozure/ccl-tests/ either.

Thats what I mean.