place: fix finalizaiton of place channels stuck in a GC'ed channel

Lack of ordering on finalization requires some care for explicit
clean-up actions in a finalizer.
This commit is contained in:
Matthew Flatt 2013-07-21 16:35:56 -06:00
parent 25c5f5e839
commit a5f26013ab
2 changed files with 20 additions and 0 deletions

View File

@ -0,0 +1,15 @@
#lang racket/base
(require racket/place)
;; Check finalization of place channels that are
;; abandoned in unreferenced place channels.
(let loop ([n 0])
(unless (= n 50000)
(define-values (i o) (place-channel))
(define-values (i2 o2) (place-channel))
(place-channel-put i o2)
(place-channel-put o i2)
(loop (add1 n))))
'ok

View File

@ -2982,6 +2982,11 @@ Scheme_Place_Async_Channel *place_async_channel_create() {
static void async_channel_refcount(Scheme_Place_Async_Channel *ch, int for_send, int delta)
{
if (!ch->lock) {
/* can happen via finalization, where the channel is already finalized
m(due to the lack of ordering on finalization) */
return;
}
mzrt_mutex_lock(ch->lock);
if (for_send)
ch->wr_ref += delta;