Thread overview
'Access Violation Error' with parallel-foreach loop
Mar 18, 2017
ooyu
Mar 18, 2017
ikod
Mar 19, 2017
ooyu
Mar 18, 2017
Vladimir Panteleev
Mar 19, 2017
ooyu
Mar 19, 2017
ikod
March 18, 2017
When i was uing parallel-foreach loop, got this error:

 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
object.Error@(0): Access Violation
----------------
0x0056CCB8 in _flushbu
0x005663C7 in fwrite
0x0041D39F in nothrow @nogc @trusted uint std.stdio.trustedFwrite!(char).trustedFwrite(shared(core.stdc.stdio._iobuf)*, const(char[]))
at C:\D\dmd2\windows\bin\..\..\src\phobos\std\stdio.d(3836)
0x004611AA in D3std6format99__T14formattedWri at C:\D\dmd2\windows\bin\..\..\src\phobos\std\format.d(556)
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄

code is here:
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
foreach( web_url; parallel(urls) ){
    try{
        auto rq = Request(); // using dlang-requests library
        auto d = rq.get( std.uri.encode(web_url) ); // file url

        File f = File(path_hash[web_url], "wb");
        f.write( d.responseBody );
        f.close();
    }
    catch(std.exception.ErrnoException e){}
}
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄

I don't understand why got Access Violation error. :-(
March 18, 2017
On Saturday, 18 March 2017 at 16:15:30 UTC, ooyu wrote:
> When i was uing parallel-foreach loop, got this error:
>
>  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
> object.Error@(0): Access Violation
> ----------------
> 0x0056CCB8 in _flushbu
> 0x005663C7 in fwrite
> 0x0041D39F in nothrow @nogc @trusted uint std.stdio.trustedFwrite!(char).trustedFwrite(shared(core.stdc.stdio._iobuf)*, const(char[]))
> at C:\D\dmd2\windows\bin\..\..\src\phobos\std\stdio.d(3836)
> 0x004611AA in D3std6format99__T14formattedWri at C:\D\dmd2\windows\bin\..\..\src\phobos\std\format.d(556)
>  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
>
> code is here:
>  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
> foreach( web_url; parallel(urls) ){
>     try{
>         auto rq = Request(); // using dlang-requests library
>         auto d = rq.get( std.uri.encode(web_url) ); // file url
>
>         File f = File(path_hash[web_url], "wb");
>         f.write( d.responseBody );
>         f.close();
>     }
>     catch(std.exception.ErrnoException e){}
> }
>  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
>
> I don't understand why got Access Violation error. :-(


Hello,
Also don't understand the reason and I can't reproduce this error. Can you try to pass ubyte[] to f.write() explicitly converting responseBody to array? Like

f.write(d.responseBody.data());


March 18, 2017
On Saturday, 18 March 2017 at 16:15:30 UTC, ooyu wrote:
> I don't understand why got Access Violation error. :-(

That looks like https://issues.dlang.org/show_bug.cgi?id=13727, though I thought a fix was included in recent DMD Windows versions.

Try using std.file.write.

March 19, 2017
On Saturday, 18 March 2017 at 20:57:59 UTC, ikod wrote:
> On Saturday, 18 March 2017 at 16:15:30 UTC, ooyu wrote:
>> When i was uing parallel-foreach loop, got this error:
>>
>>  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
>> object.Error@(0): Access Violation
>> ----------------
>> 0x0056CCB8 in _flushbu
>> 0x005663C7 in fwrite
>> 0x0041D39F in nothrow @nogc @trusted uint std.stdio.trustedFwrite!(char).trustedFwrite(shared(core.stdc.stdio._iobuf)*, const(char[]))
>> at C:\D\dmd2\windows\bin\..\..\src\phobos\std\stdio.d(3836)
>> 0x004611AA in D3std6format99__T14formattedWri at C:\D\dmd2\windows\bin\..\..\src\phobos\std\format.d(556)
>>  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
>>
>> code is here:
>>  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
>> foreach( web_url; parallel(urls) ){
>>     try{
>>         auto rq = Request(); // using dlang-requests library
>>         auto d = rq.get( std.uri.encode(web_url) ); // file url
>>
>>         File f = File(path_hash[web_url], "wb");
>>         f.write( d.responseBody );
>>         f.close();
>>     }
>>     catch(std.exception.ErrnoException e){}
>> }
>>  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
>>
>> I don't understand why got Access Violation error. :-(
>
>
> Hello,
> Also don't understand the reason and I can't reproduce this error. Can you try to pass ubyte[] to f.write() explicitly converting responseBody to array? Like
>
> f.write(d.responseBody.data());

No no, not work. :-(

when i trying this:
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
File f = File(path_hash[web_url], "wb");
f.write( d.responseBody.data() );
f.close();
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄

downloaded text file like a byte[] array:
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
[255, 216, 255, 225, 32, 246, 69, 120, 105, 102, 0, 0, 77, 77, 0, 42, 0, 0, 0, 8, 0, 7, 1 ... // this is a file that downloaded and open notepad.exe
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
March 19, 2017
On Saturday, 18 March 2017 at 22:27:27 UTC, Vladimir Panteleev wrote:
> On Saturday, 18 March 2017 at 16:15:30 UTC, ooyu wrote:
>> I don't understand why got Access Violation error. :-(
>
> That looks like https://issues.dlang.org/show_bug.cgi?id=13727, though I thought a fix was included in recent DMD Windows versions.
>
> Try using std.file.write.

Aha! Thank you.
I try again using std.file.write and input ubyte[] data.

 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
auto rq = Request();
auto d = rq.get( std.uri.encode(web_url) );
std.file.write(path_hash[web_url], d.responseBody.data);
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
working pretty :-)
March 19, 2017
On Sunday, 19 March 2017 at 00:46:29 UTC, ooyu wrote:
> On Saturday, 18 March 2017 at 22:27:27 UTC, Vladimir Panteleev wrote:
>> [...]
>
> Aha! Thank you.
> I try again using std.file.write and input ubyte[] data.
>
>  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
> auto rq = Request();
> auto d = rq.get( std.uri.encode(web_url) );
> std.file.write(path_hash[web_url], d.responseBody.data);
>  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
> working pretty :-)

It would be nice to know what actually solved problem.