Assertion Error

Moritz Maxeiner via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Sep 13 04:03:38 PDT 2017


On Wednesday, 13 September 2017 at 07:39:46 UTC, Vino.B wrote:
> On Tuesday, 12 September 2017 at 21:01:26 UTC, Moritz Maxeiner 
> wrote:
>> On Tuesday, 12 September 2017 at 19:44:19 UTC, vino wrote:
>>> Hi All,
>>>
>>> I have a small piece of code which executes perfectly 8 out 
>>> of 10 times, very rarely it throws an assertion error, so is 
>>> there a way to find which line of code is causing this error.
>>
>> You should be getting the line number as part of the crash, 
>> like here:
>>
>> --- test.d ---
>> void main(string[] args)
>> {
>> 	assert(args.length > 1);
>> }
>> --------------
>>
>> -----------------
>> $ dmd -run test.d
>>
>> core.exception.AssertError at test.d(3): Assertion failure
>> [Stack trace]
>> -----------------
>>
>> If you don't what are the steps to reproduce?
>
> Hi Max,
>
>  I tried to run the code for at least 80+ time the code ran 
> without any issue, will let you know in case if I hit the same 
> issue in feature, Below is the piece of code, plese do let me 
> know if you find any issue with the below code.
>
> Program Code:
> [...]
>  foreach (string Fs; parallel(SizeDirlst[0 .. $], 1))
>  {
> 			auto FFs = Fs.strip;
> 			auto MSizeDirList = task(&coSizeDirList, FFs, SizeDir);
> 			MSizeDirList.executeInNewThread();
> 			auto MSizeDirListData = MSizeDirList.workForce;
> 			MSresult.get ~= MSizeDirListData;
>  }

 From reading I don't see anything that I would expect to assert, 
but I am wondering why you first parallelize your work with a 
thread pool (`parallel(...)`) and then inside each (implicitly 
created) task (that is already being serviced by a thread in the 
thread pool) you create another task, have it executed in a new 
thread, and make the thread pool thread wait for that thread to 
complete servicing that new task.
This should yield the same result, but without the overhead of 
spawning additional threads:

---
foreach (string Fs; parallel(SizeDirlst[0 .. $], 1))
{
   MSresult.get ~= coSizeDirList(Fs.strip, SizeDir);
}
---


More information about the Digitalmars-d-learn mailing list