Skip to content

Commit

Permalink
place: fix finalizaiton of place channels stuck in a GC'ed channel
Browse files Browse the repository at this point in the history
Lack of ordering on finalization requires some care for explicit
clean-up actions in a finalizer.
  • Loading branch information
mflatt committed Jul 21, 2013
1 parent 25c5f5e commit a5f2601
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkgs/racket-pkgs/racket-test/tests/racket/place-in-channel-fnl.rkt
@@ -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


5 changes: 5 additions & 0 deletions racket/src/racket/src/place.c
Expand Up @@ -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;
Expand Down

0 comments on commit a5f2601

Please sign in to comment.