View Issue Details

IDProjectCategoryView StatusLast Update
0018756LazarusWidgetsetpublic2016-12-28 11:34
ReporterMiguel CastellanoAssigned ToVincent Snijders 
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
PlatformARMOSWINCEOS VersionWINCE 6.0
Product Version0.9.29 (SVN)Product Build 
Target VersionFixed in Version0.9.31 (SVN) 
Summary0018756: Thread.Synchronize() in WINCE don't wait for a method to be executed and a Critical Section don't work too
DescriptionI was encountered the Thread.Synchronize() don't work well in WINCE and Critical Section dont't work too in this platform. Please check this!
Steps To ReproduceI included a famous example of delphi of "multithread sort values" and it be compiled and executed without problems in WIN32 but when you compile for WINCE the synchronization don't work any more.

In the same context if you compile the included lazarus example "criticalsectionexample1.lpi" for WINCE and if you click
"Count with critical section" is the same as if you click "Count without critical section"
Additional InformationFPC 2.4.2
TagsNo tags attached.
Fixed in Revision32421
LazTarget-
WidgetsetWinCE
Attached Files
  • Threads.zip (383,699 bytes)
  • wincewinapi.inc.diff (687 bytes)
    Index: /home/fabiolg/lazarus/lcl/interfaces/wince/wincewinapi.inc
    ===================================================================
    --- /home/fabiolg/lazarus/lcl/interfaces/wince/wincewinapi.inc	(revisão 32361)
    +++ /home/fabiolg/lazarus/lcl/interfaces/wince/wincewinapi.inc	(cópia de trabalho)
    @@ -3596,7 +3596,7 @@
     procedure TWinCEWidgetSet.EnterCriticalSection(var CritSection: TCriticalSection);
     begin
       { An OS Compatible TCriticalSection needs to be defined}
    -  Windows.LeaveCriticalSection(LPCRITICAL_SECTION(CritSection));
    +  Windows.ENTERCRITICALSECTION(LPCRITICAL_SECTION(CritSection));
     end;
     
     {We interprete CritSection as a pointer to a LPCRITICAL_SECTION structure}
    
    wincewinapi.inc.diff (687 bytes)
  • system.pp.diff (896 bytes)
    Index: /home/fabiolg/desenvolvimento/fpcbuild251/fpcbuild/fpcsrc/rtl/wince/system.pp
    ===================================================================
    --- /home/fabiolg/desenvolvimento/fpcbuild251/fpcbuild/fpcsrc/rtl/wince/system.pp	(revisão 19058)
    +++ /home/fabiolg/desenvolvimento/fpcbuild251/fpcbuild/fpcsrc/rtl/wince/system.pp	(cópia de trabalho)
    @@ -506,8 +506,12 @@
     var
       buf: array[0..MaxPathLen] of WideChar;
     begin
    -  AnsiToWideBuf(lpName, -1, buf, SizeOf(buf));
    -  CreateEvent := CreateEventW(lpEventAttributes, bManualReset, bInitialState, buf);
    +  if lpName=nil then
    +    CreateEvent := CreateEventW(lpEventAttributes, bManualReset, bInitialState, nil)
    +  else begin
    +    AnsiToWideBuf(lpName, -1, buf, SizeOf(buf));
    +    CreateEvent := CreateEventW(lpEventAttributes, bManualReset, bInitialState, buf);
    +  end;
     end;
     
     function EventModify(h: THandle; func: DWORD): LONGBOOL;
    
    system.pp.diff (896 bytes)

Relationships

related to 0020280 closedMarco van de Voort FPC Thread.Synchronize() in WINCE don't wait for a method to be executed 

Activities

2011-02-15 01:52

 

Threads.zip (383,699 bytes)

Fabio Luis Girardi

2011-09-15 07:59

reporter   ~0051844

I think that the problem of CriticalSection is on wincewinapi.inc, on line 3585:

procedure TWinCEWidgetSet.EnterCriticalSection(var CritSection: TCriticalSection);
begin
  { An OS Compatible TCriticalSection needs to be defined}
  Windows.LEAVECRITICALSECTION(LPCRITICAL_SECTION(CritSection));
end;

It must be:


procedure TWinCEWidgetSet.EnterCriticalSection(var CritSection: TCriticalSection);
begin
  { An OS Compatible TCriticalSection needs to be defined}
  Windows.ENTERCRITICALSECTION(LPCRITICAL_SECTION(CritSection));
end;

Fabio Luis Girardi

2011-09-15 16:09

reporter   ~0051865

Last edited: 2011-09-15 16:11

The problem of the Critical Section is on Lazarus WinCE LCL. After the change of the previous note, the "criticalsectionexample1.lpi" works as expected on WinCE.

Fabio Luis Girardi

2011-09-16 01:43

reporter   ~0051895

The patch for CriticalSection problem.

2011-09-16 01:45

 

wincewinapi.inc.diff (687 bytes)
Index: /home/fabiolg/lazarus/lcl/interfaces/wince/wincewinapi.inc
===================================================================
--- /home/fabiolg/lazarus/lcl/interfaces/wince/wincewinapi.inc	(revisão 32361)
+++ /home/fabiolg/lazarus/lcl/interfaces/wince/wincewinapi.inc	(cópia de trabalho)
@@ -3596,7 +3596,7 @@
 procedure TWinCEWidgetSet.EnterCriticalSection(var CritSection: TCriticalSection);
 begin
   { An OS Compatible TCriticalSection needs to be defined}
-  Windows.LeaveCriticalSection(LPCRITICAL_SECTION(CritSection));
+  Windows.ENTERCRITICALSECTION(LPCRITICAL_SECTION(CritSection));
 end;
 
 {We interprete CritSection as a pointer to a LPCRITICAL_SECTION structure}
wincewinapi.inc.diff (687 bytes)

2011-09-17 20:56

 

system.pp.diff (896 bytes)
Index: /home/fabiolg/desenvolvimento/fpcbuild251/fpcbuild/fpcsrc/rtl/wince/system.pp
===================================================================
--- /home/fabiolg/desenvolvimento/fpcbuild251/fpcbuild/fpcsrc/rtl/wince/system.pp	(revisão 19058)
+++ /home/fabiolg/desenvolvimento/fpcbuild251/fpcbuild/fpcsrc/rtl/wince/system.pp	(cópia de trabalho)
@@ -506,8 +506,12 @@
 var
   buf: array[0..MaxPathLen] of WideChar;
 begin
-  AnsiToWideBuf(lpName, -1, buf, SizeOf(buf));
-  CreateEvent := CreateEventW(lpEventAttributes, bManualReset, bInitialState, buf);
+  if lpName=nil then
+    CreateEvent := CreateEventW(lpEventAttributes, bManualReset, bInitialState, nil)
+  else begin
+    AnsiToWideBuf(lpName, -1, buf, SizeOf(buf));
+    CreateEvent := CreateEventW(lpEventAttributes, bManualReset, bInitialState, buf);
+  end;
 end;
 
 function EventModify(h: THandle; func: DWORD): LONGBOOL;
system.pp.diff (896 bytes)

Fabio Luis Girardi

2011-09-17 20:57

reporter   ~0051958

A patch for fpcsrc/rtl/wince/system.pp
This solves the problem with Tthread.Synchronize on WinCE.

Vincent Snijders

2011-09-17 21:35

manager   ~0051960

Fabio, can you create a new issue in the FPC project with the wince/system.pp patch? Then the FPC team can look at that patch.

Fabio Luis Girardi

2011-09-17 21:43

reporter   ~0051961

Yes, perfectly!

Fabio Luis Girardi

2011-09-17 21:57

reporter   ~0051965

Done.

http://bugs.freepascal.org/view.php?id=20280

Issue History

Date Modified Username Field Change
2011-02-15 01:52 Miguel Castellano New Issue
2011-02-15 01:52 Miguel Castellano File Added: Threads.zip
2011-02-15 01:52 Miguel Castellano Widgetset => WinCE
2011-03-30 21:55 Vincent Snijders LazTarget => -
2011-03-30 21:55 Vincent Snijders Status new => acknowledged
2011-09-15 07:59 Fabio Luis Girardi Note Added: 0051844
2011-09-15 16:09 Fabio Luis Girardi Note Added: 0051865
2011-09-15 16:11 Fabio Luis Girardi Note Edited: 0051865
2011-09-16 01:43 Fabio Luis Girardi Note Added: 0051895
2011-09-16 01:45 Fabio Luis Girardi File Added: wincewinapi.inc.diff
2011-09-17 20:56 Fabio Luis Girardi File Added: system.pp.diff
2011-09-17 20:57 Fabio Luis Girardi Note Added: 0051958
2011-09-17 21:35 Vincent Snijders Note Added: 0051960
2011-09-17 21:43 Fabio Luis Girardi Note Added: 0051961
2011-09-17 21:57 Fabio Luis Girardi Note Added: 0051965
2011-09-17 22:07 Vincent Snijders Relationship added related to 0020280
2011-09-19 10:06 Vincent Snijders Fixed in Revision => 32421
2011-09-19 10:06 Vincent Snijders Status acknowledged => resolved
2011-09-19 10:06 Vincent Snijders Fixed in Version => 0.9.31 (SVN)
2011-09-19 10:06 Vincent Snijders Resolution open => fixed
2011-09-19 10:06 Vincent Snijders Assigned To => Vincent Snijders