Custom DLL function running on multiple charts

Is it correct that the function executes one after another, and not in multiple threads?

AmiVar VTest3(int NumArgs, AmiVar* ArgsTable)
{
	int nRange = (int)ArgsTable[0].val;
	char buffer[100];
	srand(time(NULL));
	AmiVar result;
	result = gSite.AllocArrayResult();

	sprintf_s(buffer, "Tempc++ %d start", nRange);
	OutputDebugStringA(buffer);

	//do some work
	for (int i = 0; i < 30000000; i++)
	{
		int x = rand() % 999999901 + 10000;
	}

	sprintf_s(buffer, "Tempc++ %d end", nRange);
	OutputDebugStringA(buffer);
	
	result.type = VAR_FLOAT;
	result.val = 1;
	return result;
}

2023-04-14_20-57-27

|20:49:40.202|newbar1|
|20:49:40.202|Tempc++ 1 start|
|20:49:40.202|newbar6|
|20:49:40.203|newbar5|
|20:49:40.203|newbar3|
|20:49:40.204|newbar4|
|20:49:40.204|newbar2|
|20:49:41.264|Tempc++ 1 end|
|20:49:41.264|Tempc++ 6 start|
|20:49:42.330|Tempc++ 6 end|
|20:49:42.330|Tempc++ 5 start|
|20:49:43.434|Tempc++ 5 end|
|20:49:43.434|Tempc++ 3 start|
|20:49:44.501|Tempc++ 3 end|
|20:49:44.501|Tempc++ 4 start|
|20:49:45.578|Tempc++ 4 end|
|20:49:45.578|Tempc++ 2 start|
|20:49:46.651|Tempc++ 2 end|

As mentioned several times on this forum and Yahoo groups, any calls to 3rd party DLLs are executed from multiple threads BUT they are protected by critical section, so they are serialized. Many existing plugins, frameworks and add-ons are not thread-safe and not re-entrant and this mechanism protects against crashes.

That is one of the reasons why you should NOT use plugin DLLs.

More details here:

Pure AFL code is mulithreading-safe and is run fully in parallel.

1 Like

This subject already exists 5 reasons why you should NOT write DLLs