oconnore / queues Goto Github PK
View Code? Open in Web Editor NEWA Common Lisp queue library with features such as non-consing thread safe queues and fibonacci priority queues
License: MIT License
A Common Lisp queue library with features such as non-consing thread safe queues and fibonacci priority queues
License: MIT License
The following code gives me an error in SBCL 1.3.10:
(let ((q (queues:make-queue :simple-cqueue)))
(queues:qpush q 42)
(queues:qpop q))
The backtrace looks like this:
Recursive lock attempt #<SB-THREAD:MUTEX "queue-lock" owner: #<SB-THREAD:THREAD "repl-thread" RUNNING {1002E58003}>>.
[Condition of type SIMPLE-ERROR]
Restarts:
0: [RETRY] Retry SLIME REPL evaluation request.
1: [*ABORT] Return to SLIME's top level.
2: [ABORT] abort thread (#<THREAD "repl-thread" RUNNING {1002E58003}>)
Backtrace:
0: (SB-THREAD::%TRY-MUTEX #<unavailable argument> #<unavailable argument>)
1: (SB-THREAD:GRAB-MUTEX #<SB-THREAD:MUTEX "queue-lock" owner: #<SB-THREAD:THREAD "repl-thread" RUNNING {1002E58003}>> :WAITP T :TIMEOUT NIL)
2: ((FLET #:WITHOUT-INTERRUPTS-BODY-359 :IN SB-THREAD::CALL-WITH-MUTEX))
3: (SB-THREAD::CALL-WITH-MUTEX #<CLOSURE (FLET SB-THREAD::WITH-MUTEX-THUNK :IN QUEUES:QSIZE) {6A4CBFB}> #<SB-THREAD:MUTEX "queue-lock" owner: #<SB-THREAD:THREAD "repl-thread" RUNNING {1002E58003}>> NIL T..
4: ((:METHOD QUEUES:QSIZE (QUEUES:SIMPLE-CQUEUE)) #<QUEUES:SIMPLE-CQUEUE 42 [1]>) [fast-method]
5: ((:METHOD QUEUES:QPOP (QUEUES:SIMPLE-QUEUE)) #<QUEUES:SIMPLE-CQUEUE 42 [1]> NIL) [fast-method]
6: ((FLET #:WITHOUT-INTERRUPTS-BODY-359 :IN SB-THREAD::CALL-WITH-MUTEX))
7: (SB-THREAD::CALL-WITH-MUTEX #<CLOSURE (FLET SB-THREAD::WITH-MUTEX-THUNK :IN QUEUES:QPOP) {6A4CE2B}> #<SB-THREAD:MUTEX "queue-lock" owner: #<SB-THREAD:THREAD "repl-thread" RUNNING {1002E58003}>> NIL T ..
8: ((:METHOD QUEUES:QPOP (QUEUES:SIMPLE-CQUEUE)) #<QUEUES:SIMPLE-CQUEUE 42 [1]>) [fast-method]
9: (SB-INT:SIMPLE-EVAL-IN-LEXENV (LET ((Q #)) (QUEUES:QPUSH Q 42) (QUEUES:QPOP Q)) #<NULL-LEXENV>)
10: (EVAL (LET ((Q #)) (QUEUES:QPUSH Q 42) (QUEUES:QPOP Q)))
Switch WITH-LOCK-HELD to WITH-RECURSIVE-LOCK-HELD in cqueue.lisp helps, but is that the right fix?
Cause: queue.lisp function qpush grows the underlying vector in two ways. Either by copying the tail or the head. In the latter, it needs to also update the "start" pointer, but doesn't.
Test:
(in-package queues)
(setf *minimum-size* 2)
(in-package cl-user)
(defparameter q (make-queue :simple-queue))
;notation: (start size vector)
(qpush q 'a) ;(0 1 (a nil))
(qpush q 'b) ;(0 2 (a b))
(qpop q) ;(1 1 (nil b))
(qpush q 'c) ;(1 2 (c b))
(qpush q 'd) ;wrongly (1 3 (c nil nil d)) instead of (3 3 (c d nil b))
;lost b, and also stuck forever as qpop's "unless" prevents popping nil
(print-queue q) ;shows (nil nil d)
Fix:
--- queues-20120703-git.orig/queue.lisp 2013-02-12 05:05:50.000000000 +0000
+++ quicklisp/dists/quicklisp/software/queues-20120703-git/queue.lisp 2013-03-26 05:49:16.000000000 +0000
@@ -111,7 +111,8 @@
for x from start below vec-size
for y from (- new-size (- vec-size start))
do (setf (aref vector y) (aref vector x)
- (aref vector x) nil)))))))
+ (aref vector x) nil))
+ (setf (start-of queue) (- new-size (- vec-size start))))))))
(setf (aref vector (%queue-last queue))
element)
(incf (size-of queue))
Please change your weird loading system to be like it is for most packages. No one wants to read up on how to load after loading. Using (queues:make-queue :simple-queue) results in "SIMPLE-QUEUE is not loaded"...
The make-queue function for the priority-queue, the parameter key in your code is 'compare', not 'comparison' as written in the Readme.
This has been a warning for the longest time:
; file: /Users/robert/quicklisp/dists/quicklisp/software/queues-20170124-git/priority-queue.lisp
; in:
; DEFMETHOD QUEUES:QUEUE-MERGE-SAFE (QUEUES:PRIORITY-QUEUE QUEUES:PRIORITY-QUEUE)
; (QUEUES::MAKE-PRIORITY-QUEUE :COMPARE
; (QUEUES:QUEUE-COMPARISON QUEUES::QUEUE1))
;
; caught STYLE-WARNING:
; undefined function: QUEUES::MAKE-PRIORITY-QUEUE
;
; compilation unit finished
; Undefined function:
; QUEUES::MAKE-PRIORITY-QUEUE
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.