Are the _d_arrayappend functions, thread-safe?

Jeff Davey jeffd at gwava.com
Tue Jun 19 11:11:55 PDT 2007


Alright, I don't know if I can assume this anymore.

I've replaced the std.string.split call with this function (that pre-allocates the array), and I can't get the app to segfault anymore.

	char[][] split(char[] data)
	{
		char[][] rtn;
		int lastPos = 0;
		int index = 0;

		int numSpaces = std.string.count(data, " ");
		rtn = new char[][numSpaces + 1];
		if (numSpaces > 0)
		{
			for (int i = 0; i < data.length; i++)
			{
				if (data[i] == ' ')
				{
					char[] word = data[lastPos .. i];
					rtn[index++] ~= data[lastPos .. i];
					lastPos = i + 1;
				}
			}
		}
		rtn[index] = data[lastPos .. data.length];

		return rtn;
	}


If I switch back to std.string.split, it dies in _d_arrayappendcT within seconds with 200 threads going on a dual-core system.

I'm also able to get it to segfault if I modify the above function to do array appends instead of pre-allocating the result.

I'm a bit at loss here, and starting to feel really uncomfortable with array appends at this point in a multi-threaded app.


Jeff Davey Wrote:

> I guess I'll assume that there isn't any problems with std.string.format, and that I have some sort of memory error somewhere.




More information about the Digitalmars-d mailing list