Threading/HTTP stream problem in 1.44

Archives Forums/BlitzMax Bug Reports/Threading/HTTP stream problem in 1.44

BlitzSupport(Posted 2011) [#1]
I'm having problems with 1.44 that don't occur in earlier versions, up to 1.42, so I'm suspecting something to do with the GCC change.

This code crashes most of the time, giving multiple EXCEPTION_ACCESS_VIOLATION errors (which I believe are per-thread).

The crashing occurs when the code involves:

1) Multiple threads;
2) Manually* reading HTTP streams (but the same code with local files is fine);
3) If the result of ReadByte/ReadLine is assigned to a variable (apparently);
4) Delays in the loop cause more reliable crashing (which might relate to #3).

* LoadString and CopyStream both work fine.

It crashes much more reliably in Debug mode than in Release mode. In fact, I can't get this test code to crash in Release (after a couple of tries), but this Code Archives downloader crashes in both modes (more often in Debug), and was the reason for me having to try and narrow this down. (I've even re-written it totally from scratch and run into the same problem!)

Function Test:Object (obj:Object)

	Local file:TStream = ReadStream (String (obj))
	
	Local t$ = ""

	If file
	
		While Not Eof (file)
		
			' ReadByte (file)		' THIS WORKS FINE WITH OR WITHOUT DELAY

			t = t + ReadByte (file) 	' THIS CRASHES (more reliably with delay than without)

			Delay 10  	 	 	' Crashes more reliably with delays; make this longer if not crashing...
			
		Wend
	
		Print t
		
		CloseStream file
	
	EndIf

	Return Null
	
End Function

Local num:Int = 10

Local thread:TThread [num]

For loop = 0 Until num
	thread [loop] = CreateThread (Test, "http::www.blitzbasic.com/codearcs/codearcs_bb/" + loop + ".bb")
Next

For loop = 0 Until num
	WaitThread thread [loop]
Next


There seems to be some connection to the time taken in the loop while reading bytes, but other than that I'm stumped!

Last edited 2011


BlitzSupport(Posted 2011) [#2]
This now appears to have been fixed by Mark -- if anyone happens to run into this problem before a new BlitzMax update, the fix is this:


Insert this...



			for( i=0;i<32;++i ){
				mark( thread->data[i] );
			}



...at line 313 of blitz_gc_ms.c

It should appear immediately before 2 other similar for loops...



... then rebuild modules.