Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2014-02

TRTLCriticalSection

13 messages · 5 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Antonio Fortuny

Hi Folks.

Lazarus 1.0.2, FPC 2.6.2, Win32 and Linux x86_64
Something goes wrong with TRTRCriticalSection. There is a difference between Windows and Linux.
In a program which will run on Win32 and Linux x86_64, using threads and all this stuff I need to protect some code from multi-threading access. One critical section looks enough to do the job.
So i code this in Win32 and Linux:

Interface uses clause is:
uses

   {$IFDEF LINUX}
   CThreads,
   {$ENDIF}
   syncobjs,
   {$IFDEF MSWINDOWS}
   windows,
   {$ENDIF}
   {$IFDEF LINUX}
   LCLIntf,
   {$ENDIF}
   Classes,
   IdContext,
   uSimplelogger,
   sitacom,
   MessageQ,
   autoupdateTCPthread,
   sqldb,
   SysUtils;
     FIniCriticalSection: TRTLCriticalSection;
     ...
     InitializeCriticalSection(FIniCriticalSection); <-----------------

compilation error
...

     EnterCriticalSection(FIniCriticalSection);
     try
         ... do a lot of things
     finally
         LeaveCriticalSection(FIniCriticalSection);
     end
     ...

On the above line marked as compilation error the compiler complains with the message
autoupdateserverthread.pas(255,48) Error: Call by var for arg no. 1 has to match exactly: Got "TRTLCriticalSection" expected "QWord" *winapi.inc*(650,11) Hint: Found declaration:
InitializeCriticalSection(var QWord);
winapi ??? Why on Linux ?
No way to get rid of this compilation error
In Win32 the program compiles and runs without errors.

Some help would be appreciated.

Antonio.

---
Ce courrier ?lectronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active. http://www.avast.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140225/fef6f935/attachment.html>

Reply by email

patspiper
to Antonio Fortuny
Antonio Fortuny wrote
Hi Folks. Lazarus 1.0.2, FPC 2.6.2, Win32 and Linux x86_64

That's an old Lazarus version. Did you test with the most recent one?

Show quoted text 45 lines
Something goes wrong with TRTRCriticalSection. There is a difference between Windows and Linux. In a program which will run on Win32 and Linux x86_64, using threads and all this stuff I need to protect some code from multi-threading access. One critical section looks enough to do the job. So i code this in Win32 and Linux: Interface uses clause is: uses {$IFDEF LINUX} CThreads, {$ENDIF} syncobjs, {$IFDEF MSWINDOWS} windows, {$ENDIF} {$IFDEF LINUX} LCLIntf, {$ENDIF} Classes, IdContext, uSimplelogger, sitacom, MessageQ, autoupdateTCPthread, sqldb, SysUtils; FIniCriticalSection: TRTLCriticalSection; ... InitializeCriticalSection(FIniCriticalSection); <----------------- compilation error ... EnterCriticalSection(FIniCriticalSection); try ... do a lot of things finally LeaveCriticalSection(FIniCriticalSection); end ... On the above line marked as compilation error the compiler complains with the message autoupdateserverthread.pas(255,48) Error: Call by var for arg no. 1 has to match exactly: Got "TRTLCriticalSection" expected "QWord"

Try putting syncobjs after LCLIntf in the uses section.

What you're seeing may be related to bug report
http://bugs.freepascal.org/view.php?id=25187

Show quoted text 7 lines
*winapi.inc*(650,11) Hint: Found declaration: InitializeCriticalSection(var QWord); winapi ??? Why on Linux ? No way to get rid of this compilation error In Win32 the program compiles and runs without errors. Some help would be appreciated.

This is odd. What is the output of View/IDE Internals/About FPC and About IDE?

Stephano
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140225/ee72d319/attachment.html>

Reply by email

Sven Barth
to Antonio Fortuny: Hi Folks. Lazarus 1.0.2, FPC 2.6.2, Win32 and Linux x86_64 Something goes wrong with…
Antonio Fortuny wrote 11 lines
Hi Folks. Lazarus 1.0.2, FPC 2.6.2, Win32 and Linux x86_64 Something goes wrong with TRTRCriticalSection. There is a difference between Windows and Linux. In a program which will run on Win32 and Linux x86_64, using threads and all this stuff I need to protect some code from multi-threading access. One critical section looks enough to do the job. So i code this in Win32 and Linux:

[snip]

Show quoted text 11 lines
On the above line marked as compilation error the compiler complains with the message autoupdateserverthread.pas(255,48) Error: Call by var for arg no. 1 has to match exactly: Got "TRTLCriticalSection" expected "QWord" *winapi.inc*(650,11) Hint: Found declaration: InitializeCriticalSection(var QWord); winapi ??? Why on Linux ? No way to get rid of this compilation error In Win32 the program compiles and runs without errors. Some help would be appreciated.

The function for initializing a TRTLCriticalSection is InitCriticalSection, not InitializeCriticalSection. If you wouldn't use the Windows unit you'd have seen this error on Windows as well.

@Michael: maybe we should add a seealso for the
Init-/Enter-/Leave-/DoneCriticalSection functions to the documentation of the TRTLCriticalSection type.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140225/03165b89/attachment.html>

Reply by email

Michael Van Canneyt
to Sven Barth
Sven Barth wrote 28 lines
Am 25.02.2014 11:22, schrieb Antonio Fortuny: Hi Folks. Lazarus 1.0.2, FPC 2.6.2, Win32 and Linux x86_64 Something goes wrong with TRTRCriticalSection. There is a difference between Windows and Linux. In a program which will run on Win32 and Linux x86_64, using threads and all this stuff I need to protect some code from multi-threading access. One critical section looks enough to do the job. So i code this in Win32 and Linux: [snip] On the above line marked as compilation error the compiler complains with the message autoupdateserverthread.pas(255,48) Error: Call by var for arg no. 1 has to match exactly: Got "TRTLCriticalSection" expected "QWord" winapi.inc(650,11) Hint: Found declaration: InitializeCriticalSection(var QWord); winapi ??? Why on Linux ? No way to get rid of this compilation error In Win32 the program compiles and runs without errors. Some help would be appreciated. The function for initializing a TRTLCriticalSection is InitCriticalSection, not InitializeCriticalSection. If you wouldn't use the Windows unit you'd have seen this error on Windows as well. @Michael: maybe we should add a seealso for the Init-/Enter-/Leave-/DoneCriticalSection functions to the documentation of the TRTLCriticalSection type.

Will do.

Michael.

Reply by email

Antonio Fortuny
to Sven Barth: [snip] The function for initializing a TRTLCriticalSection is InitCriticalSection, not…

Le 25/02/2014 12:04, Sven Barth a ?crit :

Show quoted text 27 lines
Am 25.02.2014 11:22, schrieb Antonio Fortuny: > Hi Folks. > > Lazarus 1.0.2, FPC 2.6.2, Win32 and Linux x86_64 > Something goes wrong with TRTRCriticalSection. There is a difference > between Windows and Linux. > In a program which will run on Win32 and Linux x86_64, using threads > and all this stuff I need to protect some code from multi-threading > access. > One critical section looks enough to do the job. > So i code this in Win32 and Linux: > [snip] > On the above line marked as compilation error the compiler complains > with the message > autoupdateserverthread.pas(255,48) Error: Call by var for arg no. 1 > has to match exactly: Got "TRTLCriticalSection" expected "QWord" > *winapi.inc*(650,11) Hint: Found declaration: > InitializeCriticalSection(var QWord); > winapi ??? Why on Linux ? > No way to get rid of this compilation error > In Win32 the program compiles and runs without errors. > > Some help would be appreciated. The function for initializing a TRTLCriticalSection is InitCriticalSection, not InitializeCriticalSection. If you wouldn't use the Windows unit you'd have seen this error on Windows as well.

The windows unit is used in the Win32 box (look at the conditional uses clause)

Antonio;
Show quoted text 14 lines
@Michael: maybe we should add a seealso for the Init-/Enter-/Leave-/DoneCriticalSection functions to the documentation of the TRTLCriticalSection type. Regards, Sven -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

---
Ce courrier ?lectronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active. http://www.avast.com

Reply by email

patspiper
to Mattias Gaertner: On Tue, 25 Feb 2014 11:22:57 +0100 A TRTLCriticalSection is initialized with…
Mattias Gaertner wrote 10 lines
On Tue, 25 Feb 2014 11:22:57 +0100 Antonio Fortuny wrote: > [...] > FIniCriticalSection: TRTLCriticalSection; > ... > InitializeCriticalSection(FIniCriticalSection); <----------------- > compilation error A TRTLCriticalSection is initialized with InitCriticalSection from the system unit.

I didn't notice that difference. But what about
http://bugs.freepascal.org/view.php?id=25187 ?

LCLIntf's (winapi.h) EnterCriticalsection(TCriticalSection) always takes precedence in compilation although codetools show it defined in threadh.inc: EnterCriticalsection(TRTLCriticalSection).

Stephano

Reply by email

Sven Barth
to Antonio Fortuny: Le 25/02/2014 12:04, Sven Barth a ?crit : The windows unit is used in the Win32 box (look…
Antonio Fortuny wrote 9 lines
Le 25/02/2014 12:04, Sven Barth a ?crit : > Am 25.02.2014 11:22, schrieb Antonio Fortuny: >> Some help would be appreciated. > The function for initializing a TRTLCriticalSection is > InitCriticalSection, not InitializeCriticalSection. If you wouldn't > use the Windows unit you'd have seen this error on Windows as well. The windows unit is used in the Win32 box (look at the conditional uses clause)

Yes, nevertheless you would get the same error as on Linux if you would *not* use the Windows unit on Win32. Because on Windows TRTLCriticalSection is the same as the Windows CRITICAL_SECTION thus InitializeCriticalSection will happily take an TRTLCriticalSection as argument. However on Linux TRTLCriticalSection is defined differently. That Lazarus additionally declared a different TCriticalSection and InitializeCriticalSection does not help of course... :/

Regards,
Sven

Reply by email

Mattias Gaertner
to patspiper: I didn't notice that difference. But what about…
[...] LCLIntf's (winapi.h) EnterCriticalsection(TCriticalSection) always takes precedence in compilation although codetools show it defined in threadh.inc: EnterCriticalsection(TRTLCriticalSection).

The compiler is very strict and requires the "overload" keyword for multiple functions with the same name in various units. Codetools allows to see all overloads, no matter if the "overload" keyword is missing. It depends on the context if this is a feature or a bug.

Mattias

Reply by email

Antonio Fortuny
to Antonio Fortuny: Hi Folks. Lazarus 1.0.2, FPC 2.6.2, Win32 and Linux x86_64 Something goes wrong with…

Now I get it working on both platforms.

Use InitCriticalSection and DoneCriticalsection (thanks Mattias) Using system.EnterCriticalSection and system.LeaveCriticalSection solves all the compilation problems and runs (thanks all)

Thanks again

Antonio.

---
Ce courrier ?lectronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active. http://www.avast.com

Reply by email

Mattias Gaertner
to Sven Barth: Yes, nevertheless you would get the same error as on Linux if you would *not* use the…
Show quoted text 17 lines
Am 25.02.2014 12:14, schrieb Antonio Fortuny: > > Le 25/02/2014 12:04, Sven Barth a ?crit : >> Am 25.02.2014 11:22, schrieb Antonio Fortuny: >>> Some help would be appreciated. >> The function for initializing a TRTLCriticalSection is >> InitCriticalSection, not InitializeCriticalSection. If you wouldn't >> use the Windows unit you'd have seen this error on Windows as well. > The windows unit is used in the Win32 box (look at the conditional > uses clause) Yes, nevertheless you would get the same error as on Linux if you would *not* use the Windows unit on Win32. Because on Windows TRTLCriticalSection is the same as the Windows CRITICAL_SECTION thus InitializeCriticalSection will happily take an TRTLCriticalSection as argument. However on Linux TRTLCriticalSection is defined differently. That Lazarus additionally declared a different TCriticalSection and InitializeCriticalSection does not help of course... :/

This uses the widgetsets critical sections.

I personally am satisfied with the RTL one.

Mattias

Reply by email

patspiper
to Mattias Gaertner: On Tue, 25 Feb 2014 13:22:41 +0200 I added overload to LCL Enter/LeaveCriticalSection. So…
Mattias Gaertner wrote 9 lines
On Tue, 25 Feb 2014 13:22:41 +0200 patspiper wrote: > [...] > LCLIntf's (winapi.h) EnterCriticalsection(TCriticalSection) always takes > precedence in compilation although codetools show it defined in > threadh.inc: EnterCriticalsection(TRTLCriticalSection). I added overload to LCL Enter/LeaveCriticalSection. So you don't need to bother with unit order.

Thanks.

I closed the bug report.

Stephano

Reply by email