Recent

Recent Posts

Pages: [1] 2 3 ... 10
1
General / Re: Multithreading - synchronize or not?
« Last post by Martin_fr on Today at 12:31:38 pm »
Well, only looking at the extract in the post...

The global counters have a risk of going wrong. (race condition).

You should at least use
Code: Pascal  [Select][+][-]
  1. InterlockedIncrement(Counter)
And similar for other counters.


I don't know if "aEven" is shared with something?
2
Are there any workarounds for this problem?

Since Sonoma requires Xcode Command Line Tools 15, downgrading doesn't seem to be a very practical solution?
3
Beginners / Re: Can function be used for change event
« Last post by VisualLab on Today at 12:18:23 pm »
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.

Specific events are used to handle such situations. In case of loss of focus, handling the OnExit event helps. There is no need to come up with an unusual solution.
4
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;
5
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. >
6
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
7
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)
8
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.
9
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
10
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.
Pages: [1] 2 3 ... 10

TinyPortal © 2005-2018