Getting this GPF when trying to send emails on multiple threads.
----------------------------------------------------------------------------------
Program : C:\SendEmailService\ServerService.exe
Version :
At : 23:55:42 on 2012/09/17
Reported error : EXCEPTION_ACCESS_VIOLATION - Error writing data at : 00000000h
Windows : Win XP 5.1.2600 Service Pack 3
Clarion : 6.3
Thread : 13 Field : 0 Event : 0 Keycode : 0
Error at address : 0100846Ch no line number no proc Module=C:\Clarion6\BIN\c60runx.dll 6.300.9054
Stack Trace
0042A000h Line ?=3906 no proc Src=ServerService.clw
00414558h Line ?=3906 no proc Src=ServerService.clw
00D4D0C8h Line ?=74 no proc Src=Setti_SF.CLW Module=C:\SendEmailService\Settings.dll 3.0.0.243
00D4D0C8h Line ?=74 no proc Src=Setti_SF.CLW Module=C:\SendEmailService\Settings.dll 3.0.0.243
00D4D0C8h Line ?=74 no proc Src=Setti_SF.CLW Module=C:\SendEmailService\Settings.dll 3.0.0.243
00D4D0C8h Line ?=74 no proc Src=Setti_SF.CLW Module=C:\SendEmailService\Settings.dll 3.0.0.243
00D4D0C8h Line ?=74 no proc Src=Setti_SF.CLW Module=C:\SendEmailService\Settings.dll 3.0.0.243
00D4D0C8h Line ?=74 no proc Src=Setti_SF.CLW Module=C:\SendEmailService\Settings.dll 3.0.0.243
00D4D0C8h Line ?=74 no proc Src=Setti_SF.CLW Module=C:\SendEmailService\Settings.dll 3.0.0.243
00D4D0C8h Line ?=74 no proc Src=Setti_SF.CLW Module=C:\SendEmailService\Settings.dll 3.0.0.243
00D4D0C8h Line ?=74 no proc Src=Setti_SF.CLW Module=C:\SendEmailService\Settings.dll 3.0.0.243
00D4D0C8h Line ?=74 no proc Src=Setti_SF.CLW Module=C:\SendEmailService\Settings.dll 3.0.0.243
00D4D0C8h Line ?=74 no proc Src=Setti_SF.CLW Module=C:\SendEmailService\Settings.dll 3.0.0.243
00D4D0C8h Line ?=74 no proc Src=Setti_SF.CLW Module=C:\SendEmailService\Settings.dll 3.0.0.243
00D4D0C8h Line ?=74 no proc Src=Setti_SF.CLW Module=C:\SendEmailService\Settings.dll 3.0.0.243
00D4D0C8h Line ?=74 no proc Src=Setti_SF.CLW Module=C:\SendEmailService\Settings.dll 3.0.0.243
00D4D0C8h Line ?=74 no proc Src=Setti_SF.CLW Module=C:\SendEmailService\Settings.dll 3.0.0.243
00D4D0C8h Line ?=74 no proc Src=Setti_SF.CLW Module=C:\SendEmailService\Settings.dll 3.0.0.243
00D4D0C8h Line ?=74 no proc Src=Setti_SF.CLW Module=C:\SendEmailService\Settings.dll 3.0.0.243
00D4D0C8h Line ?=74 no proc Src=Setti_SF.CLW Module=C:\SendEmailService\Settings.dll 3.0.0.243
00D4D0C8h Line ?=74 no proc Src=Setti_SF.CLW Module=C:\SendEmailService\Settings.dll 3.0.0.243
00D4D0C8h Line ?=74 no proc Src=Setti_SF.CLW Module=C:\SendEmailService\Settings.dll 3.0.0.243
010F25C8h Line ?=3023 no proc Src=wsl.cpp Module=C:\Clarion6\BIN\c60runx.dll 6.300.9054
010F25C8h Line ?=3023 no proc Src=wsl.cpp Module=C:\Clarion6\BIN\c60runx.dll 6.300.9054
010DD612h Line ?=3023 no proc Src=wsl.cpp Module=C:\Clarion6\BIN\c60runx.dll 6.300.9054
010F25C8h Line ?=3023 no proc Src=wsl.cpp Module=C:\Clarion6\BIN\c60runx.dll 6.300.9054
010F25C8h Line ?=3023 no proc Src=wsl.cpp Module=C:\Clarion6\BIN\c60runx.dll 6.300.9054
010DD606h Line ?=3023 no proc Src=wsl.cpp Module=C:\Clarion6\BIN\c60runx.dll 6.300.9054
010DA878h Line ?=3023 no proc Src=wsl.cpp Module=C:\Clarion6\BIN\c60runx.dll 6.300.9054
[01] 010AA3C8h Line ?=27 no proc Src="Library State" Module=C:\Clarion6\BIN\c60runx.dll 6.300.9054
13043A00h Line ?=246 no proc Src=NetEnc.Clw Module=C:\CLARION6\3rdParty\Bin\c60netx.dll 4.49 Built for Clarion 6 9054-9
010EA4ACh Line ?=3023 no proc Src=wsl.cpp Module=C:\Clarion6\BIN\c60runx.dll 6.300.9054
010D8F3Bh Line ?=3023 no proc Src=wsl.cpp Module=C:\Clarion6\BIN\c60runx.dll 6.300.9054
1304012Ch Line ?=246 no proc Src=NetEnc.Clw Module=C:\CLARION6\3rdParty\Bin\c60netx.dll 4.49 Built for Clarion 6 9054-9
[02] 130075DCh Line=928 Proc=CALLBACKWINDOWSRC@F Src=netdl003.clw Module=C:\CLARION6\3rdParty\Bin\c60netx.dll 4.49 Built for Clarion 6 9054-9
[03] 01091AB1h no line number no proc Module=C:\Clarion6\BIN\c60runx.dll 6.300.9054
The code is very simple, main service window loops through the email file looking for emails in the outbox. If it finds one, it adds the email ID to a global Long array[250] and then moves onto the next email its found and repeats.
Loc:ThreadCounter = 1
Loop
GlobalsLock.Wait()
Loc:EmailIDToSendArray[Loc:ThreadCounter] = Glo:EmailIDToSendArray[Loc:ThreadCounter]
GlobalsLock.Release()
IF Loc:EmailIDToSendArray[Loc:ThreadCounter] = 0
GlobalsLock.Wait()
Glo:EmailIDToSendArray[Loc:ThreadCounter] = EMA:EmailCode
GlobalsLock.Release()
Break
Else
Loc:ThreadCounter += 1
END
IF Loc:ThreadCounter > GLO:EmailThreads
Loc:ThreadCounter = 1
!Sleep(250) !Give other threads chance to send an email seems to lock app
END
END
Then I have a window which starts multiple times with a 5second delay between each Start when the app starts up and each is passed a unique thread ID so it knows what array entry to read from the Glo:EmailIDToSendArray.
In this example 10 windows (threads) were running, and a timer event checks the global var, if it finds an email id ie not zero then it looks up the email and sends it.
Timer event embed.
GlobalsLock.Wait()
Loc:EmailIDToSendArray[Loc:ThreadNo] = Glo:EmailIDToSendArray[Loc:ThreadNo]
GlobalsLock.Release()
IF Loc:EmailIDToSendArray[Loc:ThreadNo] > 0 and Loc:Sending = 0
Loc:Sending = 1
Loc:SendEmailID = Loc:EmailIDToSendArray[Loc:ThreadNo]
DO SendEmail
END
IF Loc:EmailIDToSendArray[Loc:ThreadNo] = 0 and Glo:ShutDownService = 1 and Loc:Sending = 0
Post(Event:CloseWindow)
END
Anyway this gpfs everytime unless I stipulate using just 1 thread which is out of the question because emails build up.
GlobalsLock is the critical section to avoid any threading issue.
So any suggestions?