Opened 5 months ago

Last modified 4 weeks ago

#1367 new defect

Possible memory leak related to mutexes

Reported by: megane Owned by:
Priority: not urgent at all Milestone: 4.13.0
Component: core libraries Version: 4.12.0
Keywords: srfi-18 Cc:
Estimated difficulty: insane


The following program eats up all the memory fairly quickly.

Two methods to make it not do that:

  1. Comment out the mutex-lock! and mutex-unlock! calls, or
  2. uncomment the (gc) call.

Tested with 4.12.

(use (only srfi-18 mutex-lock! mutex-unlock! thread-yield! make-thread thread-start!))
(use (only extras format))

(define (make-philosopher name mtx)
    (lambda ()
      (mutex-lock! mtx)
      ;; (print name " eating" mtx)
      (mutex-unlock! mtx)
      ;(gc) ; <- Uncommenting this seems to stop unbounded growth
      (make-philosopher name mtx)))))

(let ((mtx-food (make-mutex 'food)))
  (let lp ((i 0))
    (when (< i 5)
      (print "start philosopher-" i)
      (make-philosopher (string->symbol (format "philosopher-~a" i)) mtx-food)
      (lp (add1 i))))
  (let lp ()
    (thread-sleep! 100)

Change History (2)

comment:1 Changed 5 months ago by sjamaan

  • Milestone changed from someday to 4.13.0

comment:2 Changed 4 weeks ago by sjamaan

  • Estimated difficulty set to insane
Note: See TracTickets for help on using tickets.