← index #3627PR #425
Related · high · value 1.295
QUERY · ISSUE

raising exception in __del__ finaliser results in deadlock with multithread enabled

openby adritiumopened 2018-02-21updated 2018-02-23
bug

Original question is on uPy forum

call gc_alloc()
  GC_ENTER()
  ...
  GC_EXIT()
  call gc_collect()
    call gc_collect_start()
      GC_ENTER()
      call gc_collect_end()
        call gc_sweep()
          call "__del__" method of object if it exists (in this example an old file pointer)
            file_close() throws a "file not open" OS Exception
              OS Exception calls gc_alloc()
                gc_alloc() calls GC_ENTER() 
Result: The thread waits for the mutex to be released by itself.

The naming of m_malloc_maybe indicates it's supposed to be a conditional i.e. non-blocking allocation attempt at allocation but its implementation does not actually provide that feature; it just calls malloc and does a debug print.

void *m_malloc_maybe(size_t num_bytes) {
    void *ptr = malloc(num_bytes);
#if MICROPY_MEM_STATS
    MP_STATE_MEM(total_bytes_allocated) += num_bytes;
    MP_STATE_MEM(current_bytes_allocated) += num_bytes;
    UPDATE_PEAK();
#endif
    DEBUG_printf("malloc %d : %p\n", num_bytes, ptr);
    return ptr;
}
CANDIDATE · PULL REQUEST

Implement del

mergedby iabdalkaderopened 2014-04-04updated 2014-07-10

issue #245

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied