Re: Running Pthreads without Compiling (2nd)
Joseph Donaldson <[email protected]> Tue, 21 Dec 2021 19:14:30 +0000 (UTC)
| Newsgroups | gmane.lisp.scheme.bigloo |
|---|---|
| Message-ID | <[email protected]> |
------=_Part_1064954_173493398.1640114070117
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Hello, Glenn,
The problem you are facing with using the pthread library in the interprete=
r is that the default bigloo compiler/interpreter is statically linked agai=
nst the non-threaded version of the gc library. One solution (I am sure the=
re are more than 1) to this problem is to create a version of the interpret=
er that is linked against the threaded gc. The example below does just that=
.
------ begin interp.scm------
(module interp
=C2=A0=C2=A0 (main interp)
=C2=A0=C2=A0 (option
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ;; The GC thread safe version.
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (set! *gc-lib* 'bigloogc_mt)
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (set! *multi-threaded-gc?* #t)))
(define *src-files* '())
(define (interp-parse-args args)
=C2=A0=C2=A0 (let loop ((args (cdr args))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0 (res '()))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (cond ((null? args)
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (r=
everse! res))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ((string=
=3D? (car args) "-f")
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (l=
oop (cdr args) res))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (else
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (l=
oop (cdr args) (cons (car args) res))))))
(define (interp args)
=C2=A0=C2=A0 (library-multithread-set! #t)
=C2=A0=C2=A0 (when (>=3D (length args) 3)
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (set! *the-command-line* (interp-parse-args =
args))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (loadq (car (command-line)))))
----- end interp.scm------
Build the new interpreter with:
bigloo -O6 -o interp interp.scm=20
You can then test the new interpreter with a test file.
./interp -f test.scm
where test.scm is below.
--------begin test.scm---------(module test
=C2=A0=C2=A0 (main main)
=C2=A0=C2=A0 (library pthread))
(define (main args)
=C2=A0=C2=A0 (let ((thread (instantiate::pthread (body (lambda () (print "I=
am a thread"))))))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (thread-start-joinable! thread)
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (thread-join! thread)))--------end test.scm-=
----------
Let me know if you have any problems.
Best Regards,Joseph Donaldson
On Tuesday, December 21, 2021, 01:50:41 AM PST, Glenn Takanishi <glenn@=
neuralmachines.com> wrote: =20
=20
=20
Dec 20
Since Dec 17, I went back to Bigloo-4.3g which builds with ../lib/bigloo/4.=
3g/libbigloopthread_s-4.3g.so (the dynamic shared library).=C2=A0 I added t=
he configure option --gcparallelmark=3Dyes, and also tried --gccustomversio=
n=3Dgc-7.6.2.=C2=A0 Still get a seg-fault message when running my applicati=
on with using "(library pthread)" from the interpreter.
I'm amazed at the work Manuel did in the past on getting Boehm GC to work w=
ith Bigloo, and then adding srfi-18.=C2=A0=C2=A0 I feel a bit apologetic.
I can easily remove the "(library pthread)" line when testing with the inte=
rpreter. All seems to work okay.=C2=A0 I just add the "(library pthread)" w=
hen compiling.
So in retrospect, thanks.
Glenn
=20
------=_Part_1064954_173493398.1640114070117
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<html><head></head><body><div class=3D"ydpeae86ef6yahoo-style-wrap" style=
=3D"font-family: Helvetica Neue, Helvetica, Arial, sans-serif; font-size: 1=
3px;"><div></div>
<div dir=3D"ltr" data-setdir=3D"false">Hello, Glenn,</div><div dir=
=3D"ltr" data-setdir=3D"false"><br></div><div dir=3D"ltr" data-setdir=3D"fa=
lse">The problem you are facing with using the pthread library in the inter=
preter is that the default bigloo compiler/interpreter is statically linked=
against the non-threaded version of the gc library. One solution (I am sur=
e there are more than 1) to this problem is to create a version of the inte=
rpreter that is linked against the threaded gc. The example below does just=
that.</div><div dir=3D"ltr" data-setdir=3D"false"><br></div><div dir=3D"lt=
r" data-setdir=3D"false">------ begin interp.scm------</div><div dir=3D"ltr=
" data-setdir=3D"false"><br></div><div dir=3D"ltr" data-setdir=3D"false"><d=
iv>(module interp<br> (main interp)<br> (option<br>=
;; The GC thread safe version.<br> &nbs=
p; (set! *gc-lib* 'bigloogc_mt)<br> &nbs=
p; (set! *multi-threaded-gc?* #t)))<br><br>(define *src-files* '())<b=
r><br>(define (interp-parse-args args)<br> (let loop ((args (cd=
r args))<br> &nb=
sp; (res '()))<br> (cond ((null? =
args)<br> =
(reverse! res))<br> &=
nbsp; ((string=3D? (car args) "-f")<br> =
(loop (cdr args) res))<br>=
(else<br=
> (=
loop (cdr args) (cons (car args) res))))))<br><br>(define (interp args)<br>=
(library-multithread-set! #t)<br> (when (>=3D (=
length args) 3)<br> (set! *the-command-line* =
(interp-parse-args args))<br> (loadq (car (co=
mmand-line)))))</div><div><br></div></div><div dir=3D"ltr" data-setdir=3D"f=
alse"><br></div><div dir=3D"ltr" data-setdir=3D"false">----- end interp.scm=
------</div><div dir=3D"ltr" data-setdir=3D"false"><br></div><div dir=3D"lt=
r" data-setdir=3D"false">Build the new interpreter with:</div><div dir=3D"l=
tr" data-setdir=3D"false"><br></div><div dir=3D"ltr" data-setdir=3D"false">=
bigloo -O6 -o interp interp.scm <br></div><div dir=3D"ltr" data-setdir=3D"f=
alse"><br></div><div dir=3D"ltr" data-setdir=3D"false"><br></div><div dir=
=3D"ltr" data-setdir=3D"false">You can then test the new interpreter with a=
test file.</div><div dir=3D"ltr" data-setdir=3D"false"><br></div><div dir=
=3D"ltr" data-setdir=3D"false">./interp -f test.scm</div><div dir=3D"ltr" d=
ata-setdir=3D"false"><br></div><div dir=3D"ltr" data-setdir=3D"false">where=
test.scm is below.</div><div dir=3D"ltr" data-setdir=3D"false"><br></div><=
div dir=3D"ltr" data-setdir=3D"false">--------begin test.scm---------</div>=
<div dir=3D"ltr" data-setdir=3D"false"><div>(module test<br> (m=
ain main)<br><div> (library pthread))</div><div><br></div>(defi=
ne (main args)<br> (let ((thread (instantiate::pthread (body (l=
ambda () (print "I am a thread"))))))<br> (th=
read-start-joinable! thread)<br> (thread-join=
! thread)))</div></div><div dir=3D"ltr" data-setdir=3D"false">--------end t=
est.scm-----------</div><div dir=3D"ltr" data-setdir=3D"false"><br></div><d=
iv dir=3D"ltr" data-setdir=3D"false">Let me know if you have any problems.<=
/div><div dir=3D"ltr" data-setdir=3D"false"><br></div><div dir=3D"ltr" data=
-setdir=3D"false">Best Regards,</div><div dir=3D"ltr" data-setdir=3D"false"=
>Joseph Donaldson<br></div><div><br></div>
=20
</div><div id=3D"ydpc7a8da6fyahoo_quoted_0198467643" class=3D"ydpc7=
a8da6fyahoo_quoted">
<div style=3D"font-family:'Helvetica Neue', Helvetica, Arial, s=
ans-serif;font-size:13px;color:#26282a;">
=20
<div>
On Tuesday, December 21, 2021, 01:50:41 AM PST, Glenn T=
akanishi <[email protected]> wrote:
</div>
<div><br></div>
<div><br></div>
<div><div id=3D"ydpc7a8da6fyiv0088434094"><div>
<p>Dec 20</p>
<p>Since Dec 17, I went back to Bigloo-4.3g which builds with ../lib/bigloo=
/4.3g/libbigloopthread_s-4.3g.so (the dynamic shared library). I adde=
d the configure option --gcparallelmark=3Dyes, and also tried --gccustomver=
sion=3Dgc-7.6.2. Still get a seg-fault message when running my applic=
ation with using "(library pthread)" from the interpreter.</p>
<p>I'm amazed at the work Manuel did in the past on getting Boehm GC to wor=
k with Bigloo, and then adding srfi-18. I feel a bit apologetic=
.</p>
<p>I can easily remove the "(library pthread)" line when testing with the i=
nterpreter. All seems to work okay. I just add the "(library pthread)=
" when compiling.</p>
<p>So in retrospect, thanks.</p>
<p>Glenn</p>
<p><br></p>
</div>
</div></div>
</div>
</div></body></html>
------=_Part_1064954_173493398.1640114070117--