PR# 14489 Multithreaded program that explicitly frees small STRING locals runs out of memory

Problem Report Summary
Submitter: prestoat2000
Category: Runtime
Priority: Medium
Date: 2008/06/18
Class: Bug
Severity: Serious
Number: 14489
Release: 6.2.73753
Confidential: No
Status: Open
Responsible:
Environment: Mozilla/5.0 (X11; U; SunOS sun4u; en-US; rv:1.8.1.13) Gecko/20080328 Firefox/2.0.0.13 Solaris 10 on SPARC
Synopsis: Multithreaded program that explicitly frees small STRING locals runs out of memory

Description
A multi-threaded program with at least 20 worker threads, where each worker
repeatedly creates a STRING local with capacity 0, frees it explicitly (yes, 
this is a bad idea but it should work) and then sets the local to Void compiles
fine when finalized.

But when executed with arguments "20 100000 0" (20 workers, 100000 iterations
for each worker, STRING objects have capacity 0), it usually crashes fairly
quickly on my dual CPU SunBlade 1000 (somewhat slow) with a "No more memory"
exception.  This only seems to happen if 2 conditions are met:

1. Number of worker threads must be at least 20, for a total of 21 threads
   (in eif_threads.c, we have #define NB_THREADS_DATA 20.  Coincidence?).
   I cannot get it to fail if number of worker threads is 19, for a total of
   20 threads including main thread.

2. EIF_MEMORY_CHUNK must be set to a small value:
   setenv EIF_MEMORY_CHUNK 8192

This should be fixed by one of the following:

A. Fixing run-time bug if this is a bug
B. Not accepting EIF_MEMORY_CHUNK value of 8192 if it violates some
   internal constraint and can't work (force to larger value if 8192 too
   small to work, as is done for some other environment variables).
C. Documenting that `free' does not work correctly in a MT environment.
D. Telling me that my program has a bug :-)

To Reproduce
Finalize with attached classes and config file.
Execute system with arguments "20 100000 0".
Usually crashes with "No more memory" exception.  Sometimes crashes with a panic.
I have seen it fail with "20 3288 0" (total number of objects created is
approximately  20 * 3290 = 65760).
Problem Report Interactions
From:prestoat2000    Date:2008/06/18    Download   
Attachments for problem report #14489

Attachment: test.e     Size:640
Attachment: worker.e     Size:557
Attachment: test.ecf     Size:1238