unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Guile, pthreads and garbage collection
@ 2002-05-13 15:55 Michael J. Barillier
  2002-05-13 23:42 ` Neil Jerram
  0 siblings, 1 reply; 2+ messages in thread
From: Michael J. Barillier @ 2002-05-13 15:55 UTC (permalink / raw)


I'm designing an app with a background thread that access Guile SMOBs.
If I'm running code in a pthread, can I trust Guile not to garbage
collect a value while I'm accessing the content of the data structure
under the SMOB?

In particular, suppose I have a (Guile/Scheme) symbol whose value I'm
squirreling away in a global SCM (C) variable.  If the symbol gets
garbage collected in the main thread (no more active references) but
in the background thread I'm busy working with the C data structure,
how can I protect that structure from the free_foosmob() (or whatever)
call?  I've tried to come up with some solutions involving mutexes,
but it gets real hokey real fast.  From reading the Guile docs, it
appears that Guile scans the stack and marks any SCMs it finds on the
stack.  Unfortunately, in my case, the values I'm working with are
stored in a dynamically sized buffer--does the garbage collector also
run through the heap?  (This seems kinda expensive ...)

Or, am I worrying needlessly about something that will never happen?

Suggestions appreciated--thanks.

-- 
Michael J. Barillier
(let ((n "blackwolf") (h "pcisys.net")) (concatenate 'string n "@" h))
GnuPG public key ID: 0x35E54973
Fingerprint: EDB9 4FBC 4D0B 070C C0E3 2EE4 D822 78CE 35E5 4973
Knowledge shared is power lost. -- Aleister Crowley

_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Guile, pthreads and garbage collection
  2002-05-13 15:55 Guile, pthreads and garbage collection Michael J. Barillier
@ 2002-05-13 23:42 ` Neil Jerram
  0 siblings, 0 replies; 2+ messages in thread
From: Neil Jerram @ 2002-05-13 23:42 UTC (permalink / raw)
  Cc: guile-user

>>>>> "Michael" == Michael J Barillier <blackwolf@pcisys.net> writes:

    Michael> I'm designing an app with a background thread that access
    Michael> Guile SMOBs.  If I'm running code in a pthread, can I
    Michael> trust Guile not to garbage collect a value while I'm
    Michael> accessing the content of the data structure under the
    Michael> SMOB? [...]

    Michael> Or, am I worrying needlessly about something that will
    Michael> never happen?

For now, maybe: Guile in >1 preemptible thread doesn't currently work.
For the future, no, it isn't needless.  In other words, I'd say you're
right to be worrying about this.

The initial answer to your question is another question: why do you
want to be playing with the underlying C structure at a time where
there are no more SCM references?

If the answer is that the C structure is also used by older non-Guile
code, there's a description of a solution to this problem in the
latest CVS manual.  See the node `Extending Dia', and especially its
subnode `Dia Smobs'.  Does this help at all?  (Note that it's not
really Dia-specific at all.)

        Neil


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-05-13 23:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-05-13 15:55 Guile, pthreads and garbage collection Michael J. Barillier
2002-05-13 23:42 ` Neil Jerram

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).