Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thread koans: possible replacement for SEMAPHORE-COUNT #112

Open
phoe opened this issue May 10, 2020 · 6 comments
Open

Thread koans: possible replacement for SEMAPHORE-COUNT #112

phoe opened this issue May 10, 2020 · 6 comments

Comments

@phoe
Copy link
Contributor

phoe commented May 10, 2020

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?

@Slids
Copy link
Collaborator

Slids commented May 10, 2020

Nope, purely illustrative.

@phoe
Copy link
Contributor Author

phoe commented May 10, 2020

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

@Slids
Copy link
Collaborator

Slids commented May 10, 2020

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

@phoe
Copy link
Contributor Author

phoe commented May 10, 2020

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.

@Slids
Copy link
Collaborator

Slids commented May 10, 2020

Thats what I mean.

@phoe
Copy link
Contributor Author

phoe commented May 10, 2020

Clozure/ccl-tests#6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants