Crash in garbage collection(?) under GCC 3.3 & GCC 3.4
Øyvind Harboe
oyvind.harboe@zylin.com
Mon Jul 21 07:16:00 GMT 2003
This as Good Old crash still with us. :-)
I found it while looking for something else, and fortunally it
doesn't affect my app, but its an interesting bug.
The small app below crashes. All it does are some simple string
maniuplations w/multithreading...
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=10746
Øyvind
public class Test
{
static public String replaceAll(String in, String a, String b)
{
String t="";
int i;
for (i=0; i<(in.length()-a.length()+1); i++)
{
String c=in.substring(i, i+a.length());
if (c.equals(a))
{
t+=b;
i=i+a.length()-1;
} else
{
t+=in.substring(i, i+1);
}
}
if (i<in.length())
{
t+=in.substring(i, in.length()-1);
}
return t;
}
public static void main(String[] args)
{
Thread tr=new Thread(new Runnable()
{
public void run()
{
stressGB("second thread");
}
});
tr.start();
stressGB("first thread");
}
static void stressGB(String thread)
{
char[] abs={'a','b','c','d'};
String foo="";
for (int i=0; i<100000000; i++)
{
if ((i%1000)==0)
{
System.out.println(thread + " " + i + " " + foo);
}
double r;
r=Math.random();
foo = foo + abs[(int)(((r * (abs.length-1))))];
r=Math.random();
foo = replaceAll(foo, ""+abs[(int)(((r * (abs.length-1))))], "");
}
}
}
More information about the Java
mailing list