duplicates = multiple editions
A Classical Introduction to Modern Number Theory,Kenneth IrelandMichael Rosen
A Classical Introduction to Modern Number Theory,Kenneth IrelandMichael Rosen
;; https://en.wikipedia.org/wiki/Readers%E2%80%93writers_problem | |
(defstruct rwlock | |
(rlock (bt:make-lock)) | |
(wlock (bt:make-lock)) | |
(rtrylock (bt:make-lock)) | |
(resource (bt:make-lock)) | |
(rcount 0) | |
(wcount 0)) |
https://github.com/elixir-lang/elixir/blob/f4b5e43fc10f6fd6ef84a5ceda8aa3c37131b5a1/lib/elixir/src/elixir_def.erl | |
https://github.com/elixir-lang/elixir/blob/133fc0c40ebdc179b14d51f3e853e3264fd18b5f/lib/elixir/src/elixir_locals.erl | |
https://github.com/elixir-lang/elixir/blob/f33c00bc73650c9ff6ab641b1ad88be9c5c69fc8/lib/elixir/src/elixir_dispatch.erl |
I hereby claim:
To claim this, I am signing this object:
(let* ((mailbox (sb-concurrency:make-mailbox)) | |
(event-base (make-instance 'iolib:event-base)) | |
(control-fd (eventfd:eventfd.new 0)) | |
(thread (bt:make-thread (lambda () | |
(iolib:set-io-handler event-base | |
control-fd | |
:read (lambda (fd e ex) | |
(declare (ignorable fd e ex)) | |
(log:debug (eventfd.read control-fd)))) | |
(loop (iolib:event-dispatch event-base :one-shot t)))))) |
(defun receive-message (mailbox &key timeout) | |
"Removes the oldest message from MAILBOX and returns it as the primary | |
value, and a secondary value of T. If MAILBOX is empty waits until a message | |
arrives. | |
If TIMEOUT is provided, and no message arrives within the specified interval, | |
returns primary and secondary value of NIL." | |
(tagbody | |
;; Disable interrupts for keeping semaphore count in sync with | |
;; #msgs in the mailbox. | |
(sb-sys:without-interrupts |
(with-pinned-objects (queue me) | |
(setf (waitqueue-token queue) me) | |
(release-mutex mutex) | |
;; Now we go to sleep using futex-wait. If anyone else | |
;; manages to grab MUTEX and call CONDITION-NOTIFY during | |
;; this comment, it will change the token, and so futex-wait | |
;; returns immediately instead of sleeping. Ergo, no lost | |
;; wakeup. We may get spurious wakeups, but that's ok. | |
(setf status | |
(case (allow-with-interrupts |
/* stop all other threads by sending them SIG_STOP_FOR_GC */ | |
for(p=all_threads; p; p=p->next) { | |
gc_assert(p->os_thread != 0); | |
FSHOW_SIGNAL((stderr,"/gc_stop_the_world: thread=%lu, state=%x\n", | |
p->os_thread, thread_state(p))); | |
if((p!=th) && ((thread_state(p)==STATE_RUNNING))) { | |
FSHOW_SIGNAL((stderr,"/gc_stop_the_world: suspending thread %lu\n", | |
p->os_thread)); | |
/* We already hold all_thread_lock, P can become DEAD but | |
* cannot exit, ergo it's safe to use pthread_kill. */ |
(ql:quickload :iolib) | |
(ql:quickload :eventfd) | |
(setf control-fd (eventfd:eventfd.new 0)) | |
(setf event-base (make-instance 'iolib:event-base)) | |
(setf thread (bt:make-thread (lambda () | |
(iolib:set-io-handler event-base | |
control-fd | |
:read (lambda (fd e ex) | |
(declare (ignorable fd e ex))) |