Re: Parsec parser library...

"David McClain (as dbm at refined-audiometrics dot com)" <[email protected]> Mon, 27 Jul 2026 08:52:43 -0700
Newsgroups gmane.lisp.lispworks.general
Message-ID <[email protected]>
--Apple-Mail=_16A763ED-A9FF-4D1C-B7A6-5E7EE7B51AED
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=utf-8

.. .and yes, there is a race condition in mine=E2=80=A6

Here is how it should read for SBCL:

#+:SBCL
(let ((tlstbls   (make-hash-table
                  :weakness :key))
      (tbls-lock (mpc:make-lock)))
  (defun tlstbl ()
    (let* ((key (mpc:get-current-process))
           (doit (lambda ()
                   (or (gethash key tlstbls)
                       (setf (gethash key tlstbls) (make-hash-table))))
                 ))
      (if key
          (mpc:with-lock (tbls-lock)
            (doit))
        (doit))
      )))

The race condition that I had was a possible read while another thread =
is writing to a shared hash-table. We now hold the lock, even while =
reading.

Lispworks does not have this same problem.



--Apple-Mail=_16A763ED-A9FF-4D1C-B7A6-5E7EE7B51AED
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=utf-8

<html aria-label=3D"message body"><head><meta http-equiv=3D"content-type" =
content=3D"text/html; charset=3Dutf-8"></head><body =
style=3D"overflow-wrap: break-word; -webkit-nbsp-mode: space; =
line-break: after-white-space;">.. .and yes, there is a race condition =
in mine=E2=80=A6<div><br></div><div>Here is how it should read for =
SBCL:</div><div><br></div><div><div><font =
face=3D"Monaco">#+:SBCL</font></div><div><font face=3D"Monaco">(let =
((tlstbls &nbsp; (make-hash-table</font></div><div><font =
face=3D"Monaco">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =
&nbsp; :weakness :key))</font></div><div><font face=3D"Monaco">&nbsp; =
&nbsp; &nbsp; (tbls-lock (mpc:make-lock)))</font></div><div><font =
face=3D"Monaco">&nbsp; (defun tlstbl ()</font></div><div><font =
face=3D"Monaco">&nbsp; &nbsp; (let* ((key =
(mpc:get-current-process))</font></div><div><font face=3D"Monaco">&nbsp; =
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(doit (lambda =
()</font></div><div><font face=3D"Monaco">&nbsp; &nbsp; &nbsp; &nbsp; =
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(or (gethash key =
tlstbls)</font></div><div><font face=3D"Monaco">&nbsp; &nbsp; &nbsp; =
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(setf =
(gethash key tlstbls) (make-hash-table))))</font></div><div><font =
face=3D"Monaco">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =
&nbsp;))</font></div><div><font face=3D"Monaco">&nbsp; &nbsp; &nbsp; (if =
key</font></div><div><font face=3D"Monaco">&nbsp; &nbsp; &nbsp; &nbsp; =
&nbsp; (mpc:with-lock (tbls-lock)</font></div><div><font =
face=3D"Monaco">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =
(doit))</font></div><div><font face=3D"Monaco">&nbsp; &nbsp; &nbsp; =
&nbsp; (doit))</font></div><div><font face=3D"Monaco">&nbsp; &nbsp; =
&nbsp; )))</font></div><div><br></div><div>The race condition that I had =
was a possible read while another thread is writing to a shared =
hash-table. We now hold the lock, even while =
reading.</div><div><br></div><div>Lispworks does not have this same =
problem.</div><div><br></div><div><br></div></div></body></html>=

--Apple-Mail=_16A763ED-A9FF-4D1C-B7A6-5E7EE7B51AED--

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
[email protected]
http://www.lispworks.com/support/lisp-hug.html