[fpc-pascal] USB Human Interface Devices
Jean SUZINEAU
Jean.Suzineau at wanadoo.fr
Wed Aug 28 13:04:12 CEST 2019
Hello,
It seems you didn't initialized you critical section using
InitCriticalSection.
The documentation of EnterCriticalSection :
https://www.freepascal.org/docs-html/rtl/system/entercriticalsection.html
The one of InitCriticalSection:
https://www.freepascal.org/docs-html/rtl/system/initcriticalsection.html
At the end, you need to call DoneCriticalSection to release the
associated system resources (
https://www.freepascal.org/docs-html/rtl/system/donecriticalsection.html).
Note: these is related to freepascal implementation of critical
sections, in windows API, the function names are slightly different,
InitializeCriticalSection/EnterCriticalSection/DeleteCriticalSection
(https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-entercriticalsection)
Le 28/08/2019 à 01:50, James Richters a écrit :
> One thing I wasn't able to duplicate however was the use of EnterCriticalsection(criticalSection); and LeaveCriticalsection(criticalSection); when writing to shared variables. If I try to ever use EnterCriticalsection(criticalSection); in the read thread, My program just instantly locks up and I can't even break out of it. If I try to use it in the main program I instantly get
> EAccessViolation: Access violation
> $00007FFF18A2DF23
> $00007FFF189E9BBC
> $00007FFF189E9AD0
> $000000010000DCDA
> $000000010000D54B
> $000000010000218B PROCESS_USB_DATA, line 475 of WHB04B-4_test.pas
> $0000000100002B37 SIMPLETERMINAL, line 641 of WHB04B-4_test.pas
> $0000000100002DDD USE_MPG_DEVICE, line 675 of WHB04B-4_test.pas
> $0000000100002F93 main, line 699 of WHB04B-4_test.pas
> $0000000100002FE6
> $0000000100011350
> $0000000100001980
> $00007FFF17B47E94
> $00007FFF18A4A251
> Line 475 is EnterCriticalsection(criticalSection);
> I left where I had the criticalsection stuff in the program but commented out. It does seem to work fine without it though.. since the read, I am curious what I'm doing wrong, or if I need to do something else because I'm on Windows.
More information about the fpc-pascal
mailing list