Recent

Recent Posts

Pages: [1] 2 3 ... 10
1
General / Multithreading - synchronize or not?
« Last post by mika on Today at 12:08:20 pm »
I created this example based of my multithreading app.

How to do synchronization in this? I kinda works with no syncronization at all...

relevant snipet from attached example:
Code: Pascal  [Select][+][-]
  1. procedure TThreadEven.Execute;
  2. var cur : qword;
  3.     k: longword;
  4.     OddVal : qword;
  5.     EvenVal : qword;
  6.     er : longword;
  7. begin
  8.      OddVal:= 1;
  9.      EvenVal:=1;
  10.      while (not Terminated)  do
  11.      begin
  12.           inc(Counter); //-- spin count
  13.  
  14.           if FlagEven = 0 then
  15.           begin
  16.                FlagEven:=1;
  17.                for k:=0 to cBigSize-1 do aEven[k]:=EvenVal;
  18.                inc(EvenVal);
  19.                inc(CountOutData);
  20.                FlagEven:=2; //-- send data
  21.           end;
  22.  
  23.           if FlagOdd = 2 then //-- incoming data from "Odd" thread
  24.           begin
  25.                er:=0;
  26.                FlagOdd:=3;
  27.                for k:=0 to cSize-1 do if aOdd[k]<>OddVal then inc(er);
  28.                inc(OddVal);
  29.                inc(CountInData);
  30.                if er<>0 then inc(CountErData);
  31.                FlagOdd:=0; //-- data recived and processed, ready for new
  32.           end;
  33.      end;
  34. end;
  35.  
  36.  
  37. procedure TThreadOdd.Execute;
  38. var cur : qword;
  39.     k: longword;
  40.     OddVal : qword;
  41.     EvenVal : qword;
  42.     er : longword;
  43.  
  44. begin
  45.      OddVal:= 1;
  46.      EvenVal:=1;
  47.      while (not Terminated)  do
  48.      begin
  49.           inc(Counter); //-- spin count
  50.  
  51.           if FlagOdd = 0 then
  52.           begin
  53.                FlagOdd:=1;
  54.                for k:=0 to cSize-1 do aOdd[k]:=OddVal;
  55.                inc(OddVal);
  56.                inc(CountOutData);
  57.                FlagOdd:=2; //-- send data
  58.           end;
  59.  
  60.           if FlagEven = 2 then //-- incoming data from "Even" thread
  61.           begin
  62.                er:=0;
  63.                FlagEven:=3;
  64.                for k:=0 to cBigSize-1 do if aEven[k]<>EvenVal then inc(er);
  65.                inc(EvenVal);
  66.                inc(CountInData);
  67.                if er<>0 then inc(CountErData);
  68.                FlagEven:=0; //-- data recived and processed, ready for new
  69.           end;
  70.  
  71.      end;
  72. end;
2
Unix / Re: A fairly simple sound solution?
« Last post by Giorgos on Today at 11:45:19 am »
I found a simple solution, based on executing shell programs.
(In this case, a console media player).

Code: Pascal  [Select][+][-]
  1. program sound;
  2.  
  3. uses Unix;
  4.  
  5. begin
  6.   fpSystem('play -q ~/TEMPG/SAMPLE.WAV');
  7. end.

A short WAV file, somewhere in the filesystem will do.
I used play, but also aplay, paplay or any console media player will do.

PS. It written ages ago. Today's FPC, throughs a warning (although the program compiles and run flawlessly).

Code: Pascal  [Select][+][-]
  1. >fpc PLAY.PAS
  2. Free Pascal Compiler version 3.0.4+dfsg-22 [2019/01/24] for x86_64
  3. Copyright (c) 1993-2017 by Florian Klaempfl and others
  4. Target OS: Linux for x86-64
  5. Compiling PLAY.PAS
  6. PLAY.PAS(6,7) Warning: Symbol "fpSystem" is deprecated: "use ansistring version"
  7. Linking PLAY
  8. /usr/bin/ld.bfd: warning: link.res contains output sections; did you forget -T?
  9. 7 lines compiled, 0.2 sec
  10. 1 warning(s) issued
  11. >
3
Beginners / Re: Can function be used for change event
« Last post by cdbc on Today at 11:42:02 am »
Hi
I use this technique all the time, e.g.: in Iterator-Callbacks, where the result determines if we continue or stop iteration. Also some, if not many Events, benefit from a returning result.
But, even though exactly 'TNotifyEvent' would be hard to change nowadays, there's nothing stopping you from defining your own event-functions  ;)
Regards Benny
4
Editor / Re: match automatic highlight on NON matching text?
« Last post by Чебурашка on Today at 11:35:14 am »
Hi
Correct english would be: AnObject & AnIdentifier. Elegant too...
/AObject/ really hurts my eyes.
Just my 2 cents
Regards Benny

Despite I love the beauty of English, I try to focus on efficiency/simplicity because I believe I am not writing prose or poetry, just software.
Moreover it is just pascal/delphi IDEs favouring this kind of parameters naming, other languages I worked with don't do the same (C,C++,Java,C#,Ruby,Perl,PHP,VB)
5
Beginners / Can function be used for change event
« Last post by Joanna on Today at 11:30:10 am »
Has anyone ever tried using a function with boolean result for a change event?
Currently I use procedure change_event (sender:tobject);

Sometimes change events get activated when no change actually occurred such as when a tedit loses focus. It would help handle this event easier with something like

Function change_event (sender:tobject):boolean;

So I could do Something like
If not Sendermethod.change_event (sender)
    Then exit;

I believe This type of technique is used for the function encode date and other things.
6
Editor / Re: match automatic highlight on NON matching text?
« Last post by cdbc on Today at 11:30:08 am »
Hi
Correct english would be: AnObject & AnIdentifier. Elegant too...
/AObject/ really hurts my eyes.
Just my 2 cents
Regards Benny
7
Editor / Re: match automatic highlight on NON matching text?
« Last post by WooBean on Today at 11:15:00 am »
Btw, and without wanting to interfere with your teams guidelines, but have you considered: AnObject instead of Aobject ?

Just paralel observation from core Lazarus source code -  there are 22 "AIdentifier" and 31 "AnIdentifier" usages.
We can survive it, anyway.
8
TAChart / Re: Tchart with dual numbers at the axis
« Last post by wp on Today at 10:48:18 am »
The usual way to display unusual values as axis labels is to put them into an extra TListChartSource which then is assigned to the axis' Marks.Source:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   i: Integer;
  4. begin
  5.   ListChartSource1.Clear;
  6.   for i := 0 to 20 do
  7.     ListChartSource1.Add(i*64, i*64);
  8.   Chart1.BottomAxis.Marks.Source := ListChartSource1;
  9. end;
9
Code: Pascal  [Select][+][-]
  1. $ ./compiler/ppcrossmipsel test.pas -Fu./rtl/ps1 -Fu./rtl/inc -Tps1 -a -XP/usr/local/mipsel-unknown-elf/bin/mipsel-unknown-elf- -Cfnone -n -vut
  2. Warning: Source OS Redefined!
  3. Compiler: /home/key-real/vip-code/source/compiler/ppcrossmipsel
  4. Using executable path: /home/key-real/vip-code/source/compiler/
  5. Using unit path: ./rtl/ps1/
  6. Using unit path: ./rtl/inc/
  7. Using unit path: ./compiler/
  8. Using library path: ./rtl/ps1/
  9. Using library path: ./rtl/inc/
  10. Using library path: ./compiler/
  11. Using object path: ./rtl/ps1/
  12. Using object path: ./rtl/inc/
  13. Using object path: ./compiler/
  14. Searching file test.pas... found
  15. (PROGRAM)  Registering new unit SYSTEM
  16. (PROGRAM)  Load from PROGRAM (implementation) unit SYSTEM
  17. (SYSTEM)   Loading unit SYSTEM
  18. Unitsearch: system.ppu
  19. Searching file system.ppu... not found
  20. Searching file SYSTEM.PPU... not found
  21. Unitsearch: system.pp
  22. Searching file system.pp... not found
  23. Searching file SYSTEM.PP... not found
  24. Unitsearch: system.pas
  25. Searching file system.pas... not found
  26. Searching file SYSTEM.PAS... not found
  27. Unitsearch: ./rtl/ps1/system.ppu
  28. Searching file ./rtl/ps1/system.ppu... found
  29. PPU Loading ./rtl/ps1/system.ppu
  30. (SYSTEM)   PPU Name: ./rtl/ps1/system.ppu
  31. (SYSTEM)   PPU Time: 2024/04/23 10:36:02
  32. (SYSTEM)   PPU Flags: 4224
  33. (SYSTEM)   PPU Crc: 81615BB2
  34. (SYSTEM)   PPU Crc: 3FC14DEF (intfc)
  35. (SYSTEM)   PPU Crc: DE388206 (indc)
  36. (SYSTEM)   Number of definitions: 2958
  37. (SYSTEM)   Number of symbols: 7783
  38. (SYSTEM)   PPU Source: ./rtl/ps1/system.pp time 2024/04/22 08:41:06
  39. (SYSTEM)   PPU Source: systemh.inc not found
  40. (SYSTEM)   PPU Source: sysosh.inc not available
  41. (SYSTEM)   PPU Source: rtldefs.inc not available
  42. (SYSTEM)   PPU Source: filerec.inc not available
  43. (SYSTEM)   PPU Source: textrec.inc not available
  44. (SYSTEM)   PPU Source: innr.inc not available
  45. (SYSTEM)   PPU Source: cpuh.inc not available
  46. (SYSTEM)   PPU Source: ../mips/cpuh.inc not available
  47. (SYSTEM)   PPU Source: currh.inc not available
  48. (SYSTEM)   PPU Source: ustringh.inc not available
  49. (SYSTEM)   PPU Source: setjumph.inc not available
  50. (SYSTEM)   PPU Source: ../mips/setjumph.inc not available
  51. (SYSTEM)   PPU Source: rttih.inc not available
  52. (SYSTEM)   PPU Source: objpash.inc not available
  53. (SYSTEM)   PPU Source: varianth.inc not available
  54. (SYSTEM)   PPU Source: dynarrh.inc not available
  55. (SYSTEM)   PPU Source: compproc.inc not available
  56. (SYSTEM)   PPU Source: heaph.inc not available
  57. (SYSTEM)   PPU Source: threadh.inc not available
  58. (SYSTEM)   PPU Source: dynlibh.inc not available
  59. (SYSTEM)   PPU Source: resh.inc not available
  60. (SYSTEM)   PPU Source: excepth.inc not available
  61. (SYSTEM)   PPU Source: system.inc not available
  62. (SYSTEM)   PPU Source: sysos.inc not available
  63. (SYSTEM)   PPU Source: mips.inc not available
  64. (SYSTEM)   PPU Source: ../mips/mips.inc not available
  65. (SYSTEM)   PPU Source: generic.inc not available
  66. (SYSTEM)   PPU Source: set.inc not available
  67. (SYSTEM)   PPU Source: ../mips/set.inc not available
  68. (SYSTEM)   PPU Source: genset.inc not available
  69. (SYSTEM)   PPU Source: gencurr.inc not available
  70. (SYSTEM)   PPU Source: sstrings.inc not available
  71. (SYSTEM)   PPU Source: int64p.inc not available
  72. (SYSTEM)   PPU Source: ../mips/int64p.inc not available
  73. (SYSTEM)   PPU Source: int64.inc not available
  74. (SYSTEM)   PPU Source: astrings.inc not available
  75. (SYSTEM)   PPU Source: ustrings.inc not available
  76. (SYSTEM)   PPU Source: aliases.inc not available
  77. (SYSTEM)   PPU Source: rttidecl.inc not available
  78. (SYSTEM)   PPU Source: dynarr.inc not available
  79. (SYSTEM)   PPU Source: objpas.inc not available
  80. (SYSTEM)   PPU Source: except.inc not available
  81. (SYSTEM)   PPU Source: variant.inc not available
  82. (SYSTEM)   PPU Source: rtti.inc not available
  83. (SYSTEM)   PPU Source: setjump.inc not available
  84. (SYSTEM)   PPU Source: ../mips/setjump.inc not available
  85. (SYSTEM)   PPU Source: sysheap.inc not available
  86. (SYSTEM)   PPU Source: heap.inc not available
  87. (SYSTEM)   PPU Source: thread.inc not available
  88. (SYSTEM)   PPU Source: threadvr.inc not available
  89. (SYSTEM)   PPU Source: dynlib.inc not available
  90. (SYSTEM)   PPU Source: sysfile.inc not available
  91. (SYSTEM)   PPU Source: text.inc not available
  92. (SYSTEM)   PPU Source: file.inc not available
  93. (SYSTEM)   PPU Source: typefile.inc not available
  94. (SYSTEM)   PPU Source: isotmp.inc not available
  95. (SYSTEM)   PPU Source: sysdir.inc not available
  96. (SYSTEM)   PPU Source: sysres.inc not available
  97. (SYSTEM)   Finished loading unit SYSTEM
  98. Searching file test.pas... found
  99. Searching file test.pas... found
  100. Searching file test.pas... found
  101. (PROGRAM)  Registering new unit FPINTRES
  102. (PROGRAM)  Load from PROGRAM (implementation) unit FPINTRES
  103. (FPINTRES) Loading unit FPINTRES
  104. Unitsearch: fpintres.ppu
  105. Searching file fpintres.ppu... not found
  106. Searching file FPINTRES.PPU... not found
  107. Unitsearch: fpintres.pp
  108. Searching file fpintres.pp... not found
  109. Searching file FPINTRES.PP... not found
  110. Unitsearch: fpintres.pas
  111. Searching file fpintres.pas... not found
  112. Searching file FPINTRES.PAS... not found
  113. Unitsearch: ./rtl/ps1/fpintres.ppu
  114. Searching file ./rtl/ps1/fpintres.ppu... not found
  115. Searching file ./rtl/ps1/FPINTRES.PPU... not found
  116. Unitsearch: ./rtl/ps1/fpintres.pp
  117. Searching file ./rtl/ps1/fpintres.pp... not found
  118. Searching file ./rtl/ps1/FPINTRES.PP... not found
  119. Unitsearch: ./rtl/ps1/fpintres.pas
  120. Searching file ./rtl/ps1/fpintres.pas... not found
  121. Searching file ./rtl/ps1/FPINTRES.PAS... not found
  122. Unitsearch: ./rtl/inc/fpintres.ppu
  123. Searching file ./rtl/inc/fpintres.ppu... not found
  124. Searching file ./rtl/inc/FPINTRES.PPU... not found
  125. Unitsearch: ./rtl/inc/fpintres.pp
  126. Searching file ./rtl/inc/fpintres.pp... found
  127. Searching file test.pas... found
  128. test.pas(1,6) Error: Compilation raised exception internally
  129. Fatal: Compilation aborted
  130. An unhandled exception occurred at $0000000000570E35:
  131. EAccessViolation: Access violation
  132.   $0000000000570E35  push,  line 1936 of symdef.pas
  133.   $00000000007C68FE  AddUnit,  line 204 of pmodules.pas
  134.   $00000000007C7634  CheckAddUnit,  line 384 of pmodules.pas
  135.   $00000000007C72FF  loaddefaultunits,  line 426 of pmodules.pas
  136.   $00000000007CE667  proc_program,  line 2837 of pmodules.pas
  137.   $00000000004E1779  compile_module,  line 488 of parser.pas
  138.   $0000000000517559  continue,  line 269 of ctask.pas
  139.   $00000000005177BF  processqueue,  line 334 of ctask.pas
  140.   $000000000043E12F  Compile,  line 310 of compiler.pas
  141.   $0000000000401496  $main,  line 308 of pp.pas
  142.   $000000000043372D  SysEntry,  line 332 of system.pp
  143.  
  144.  
10
General / Re: Generics - correct syntax
« Last post by VisualLab on Today at 10:23:16 am »
I don't know what to tell you?

Basically the question was for people who know something about the documentation detailing generic types in FPC mode. Of course, I do not rule out that there is no detailed documentation on this subject. Still, it would be very useful. Programming using the "Macayev method" (also known as the "Grope method", "battle reconnaissance" or "trial and error :)) is ineffective and error-prone.
Pages: [1] 2 3 ... 10

TinyPortal © 2005-2018