Recent

Recent Posts

Pages: [1] 2 3 ... 10
1
General / Re: Multithreading - synchronize or not?
« Last post by mika on Today at 01:48:51 pm »
https://en.wikipedia.org/wiki/Memory_barrier

Assuming ONLY ONE thread each:

...
If you only write to aEven, so you may only need a WriteBarrier on entry into the "if" block. You can check for each block if you read, write, or read/write shared data ... Though the "inc" is a read/write...


yes "ONLY ONE thread each", ONLY ONE  at a time

FlagEven:=1; is for perfomance measurments with "EverSpin" thread thats count time spent no each flag state. Agree, not needed in final product.

I did try memory barrier like "sfence" , "lfence", "mfence".. but i can not mesure diference in perfomance. Results are inconsitent as is, and effect of "fneces" is not distinguishable.  maybe i have wrongly constructed exaple.

From documentation about "fence" i understand that they are local to thread instructions and only help to keep in check "out of order" execution of instructions. Nothing about faster or forced data synchroniztion with main memory.
2
Beginners / Re: Can function be used for change event
« Last post by Joanna on Today at 01:48:36 pm »
In this case the event is oneditingdone I suppose different controls have different types of change events but I try to handle them all through one event procedure. Which is why it’s important to know if the control actually changed..,

I have no idea what would be involved in creating a new type of event that uses a function instead of procedure but acts like tnotifyevent. How are events created? Can I create one in my tedit descendant similar to oneditingdone ?
3
Unix / Re: A fairly simple sound solution? [SOLVED]
« Last post by KodeZwerg on Today at 01:48:26 pm »
Besides, Windows multimedia solutions are not that simple either (although much better designed and operated). Unfortunately, multimedia support requires knowledge of API and/or external libraries. There are no shortcuts here.
I just typed here in a hurry, should be working without even reading api, so it might be wrong but anyway not overcomplicated.
Code: Pascal  [Select][+][-]
  1. uses
  2.  MMSystem;
  3.  
  4. procedure PlayWavFile(const FileName: string);
  5. begin
  6.  sndPlaySound(PChar(FileName), snd_Async or snd_NoDefault);
  7. end;
  8.  
  9. begin
  10.  PlayWavFile('C:\path\to\your\sound.wav');
  11. end.
Or do it like the OP does and simple execute the wave file to start systems playback (in hope something useful is associated with).
For a more custom type of usage where you have more control over the playback, there are methods to be used and I agree, on that part you should start to read to know how its used correct.
From point of api, you can start at SoundMixer to select an output device over to decode audio to finally feed the output device with the buffered raw audio data.
Possibilities are endless, whatever you wish, the api provide it. If its about Mono/Stereo/Custom, Volume, DSP effects, visualized, equalizer and and and... api can do the job.
4
General / Re: compiler error in unit
« Last post by Zvoni on Today at 01:45:44 pm »
TPoint already declared in different unit?

btw: Is Line 54 a Typo? PLONC
5
General / compiler error in unit
« Last post by paule32 on Today at 01:36:37 pm »
Hello,
during compile, I stuck on line: 57 (see attached image).
I get the compiler error:
FPC_WinTypes.pas(57) Fatal: Syntax error, "UNIT" expected but "end of file" found

And this is the content:

Code: Pascal  [Select][+][-]
  1. // ---------------------------------------------------------------------------
  2. // File:   FPC_WinTypes.pas
  3. // Author: (c) 2024 Jens Kallup - paule32
  4. // All rights reserved
  5. //
  6. // only for education, and non-profit usage !
  7. // ---------------------------------------------------------------------------
  8. unit FPC_WinTypes;
  9. interface
  10.  
  11. uses fpc_types;
  12. // ---------------------------------------------------------------------------
  13. // win32api constants, and variables ...
  14. // ---------------------------------------------------------------------------
  15. type BOOL      = LongBool;       // true or false
  16.  
  17. type PVOID     = Pointer;
  18. type LPVOID    = ^PVOID;
  19. type LPCVOID   = ^LPVOID;
  20.  
  21. type HANDLE    = PVOID;
  22. type FARPROC   = PVOID;
  23.  
  24. type THANDLE   =    DWORD;      // onject handle
  25. type PHandle   = ^THANDLE;
  26.  
  27. type LCID      = DWord;         // a local identifier
  28. type LANGID    = DWord;         // a language identifier
  29.  
  30. type WPARAM    = DWord;         // 32-bit message parameter
  31. type LPARAM    = DWord;         // 32-bit message parameter
  32.  
  33. type LRESULT   = DWord;         // 32-bit unsigned return value
  34. type HRESULT   = DWord;         // 32-bit signed   return value
  35.  
  36. type HINSTANCE = HANDLE;        // a handle to an instance
  37. type HLOCAL    = HANDLE;        // a handle to a local memory block
  38. type HMODULE   = HINSTANCE;     // a handle to a module (.dll)
  39.  
  40. type HWND      = DWord;         // a handle to a window
  41. type ATOM      = DWord;         // local/global atom index for a string
  42.  
  43. type HGLOBAL   = THandle;       // a globally memory allocated handle
  44.  
  45. type PAnsiString = ^AnsiString;
  46. type LPCSTR      = PAnsiString;
  47. type LPCWSTR     = PAnsiString;
  48.  
  49. //type FARPROC   = Pointer;
  50.  
  51. type LPCTSTR   = LPCSTR;
  52.  
  53. type LONG_PTR  = DWORD;
  54. type PLONC_PTR = ^LONG_PTR;
  55.  
  56. type
  57.     PPoint = ^TPoint;
  58.     TPoint = record
  59.         x: DWORD;
  60.         y: DWORD;
  61.     end;
  62. type
  63.     PMessage = ^TMessage;
  64.     TMessage = record
  65.         hwnd     : HWND;
  66.         message  : DWORD;
  67.         wParam   : WPARAM;
  68.         lParam   : LPARAM;
  69.         time     : DWORD;
  70.         pt       : TPOINT;
  71.         lPrivate : DWORD;
  72.     end;
  73. // ---------------------------------------------------------------------------
  74. // security structures ...
  75. // ---------------------------------------------------------------------------
  76. type
  77.     POverlapped = ^TOverlapped;
  78.     _OVERLAPPED = record
  79.         Internal      : ^DWORD ;
  80.         InternalHigh  : ^DWORD ;
  81.         Offset        :  DWORD ;
  82.         OffsetHigh    :  DWORD ;
  83.         hEvent        : THandle;
  84.     end;
  85.     TOverlapped = _OVERLAPPED;
  86.  
  87.     PSECURITY_ATTRIBUTES  = ^TSECURITYATTRIBUTES;
  88.     LPSECURITY_ATTRIBUTES = ^TSECURITYATTRIBUTES;
  89.     PSecurityAttributes   = ^TSecurityAttributes;
  90.     TSECURITYATTRIBUTES  = record
  91.         nLength              : DWORD  ;
  92.         lpSecurityDescriptor : Pointer;
  93.         bInheritHandle       : BOOL   ;
  94.     end;
  95.  
  96. implementation
  97.  
  98. end.

So, what is going on ?
6
Although I would like smaller files for testing. My drive only has 15 gb free space, so I cannot run the billion line generator

Did you see that the generator has a command line switch "-n" to set the amount of generated lines? This way you can create files for testing of any size.
7
General / Re: Multithreading - synchronize or not?
« Last post by Martin_fr on Today at 01:08:18 pm »
https://en.wikipedia.org/wiki/Memory_barrier

So between modifying the data in "aEven" and setting "EvenFlag" for the other thread you need a barrier. (write barrier).

After checking the flag, and before reading the data, you need a readbarrier.



Assuming ONLY ONE thread each:

Code: Pascal  [Select][+][-]
  1.           if FlagEven = 0 then  // this can be a dirty read, no problem
  2.           begin
  3. //               FlagEven:=1; // not needed
  4. ReadWriteBarrier; // Don't read the below data before FlagEven really is 0
  5.        // Don't write it either....
  6.                for k:=0 to cBigSize-1 do aEven[k]:=EvenVal;
  7. // If I am correct then the other thread won't access them due to FlagEven => so "inc" is ok, no InterlockedIncrement needed)
  8.                inc(EvenVal);
  9.                inc(CountOutData);
  10. WriteBarrier; // Don't write the below, before all the above has been written
  11.                FlagEven:=2; //-- send data
  12.           end;
If you only write to aEven, so you may only need a WriteBarrier on entry into the "if" block. You can check for each block if you read, write, or read/write shared data ... Though the "inc" is a read/write...



You still need InterlockedIncrement for the Counter that is not protected by any flags.
8
General / Re: Multithreading - synchronize or not?
« Last post by Martin_fr on Today at 01:06:32 pm »
"Counter" is member of thread class. It is local to thread, there is no conflict.

aEven, aOdd is global array, that one thread writes and other reads. Flag indicates when to read when to write.

So 2 threads total only?

Then why set               
Code: Pascal  [Select][+][-]
  1. FlagEven:=1;
There is no thread checking for that. The thread that wanted it 0 is in the "if" block, the other one will wait till it is 2. So you could leave it 0?


Quote
Interlocked, does include the needed barriers.

"Interlocked" you mean:
lock cmpxchg [mem], reg
or
lock xadd [mem], reg ?

Both of them include (afaik) all the read/write barriers that you need. Any InterLocked... (or asm lock ...) should do that.
9
General / Re: Multithreading - synchronize or not?
« Last post by mika on Today at 12:55:41 pm »
"Counter" is member of thread class. It is local to thread, there is no conflict.

aEven, aOdd is global array, that one thread writes and other reads. Flag indicates when to read when to write.

If there is ONLY ONE thread of each then... Well, afaik technically you need Read/Write barriers in some cases. But it may work without. Though, I would put a "WriteBarrier;" in front of the assignments setting it to 2 or 0 (before the "end" of the "if"'s begin/end block). 
yes it is  "ONLY ONE thread of each" and ONLY ONE at a time.

Interlocked, does include the needed barriers.

"Interlocked" you mean:
lock cmpxchg [mem], reg
or
lock xadd [mem], reg ?

10
Unix / Re: A fairly simple sound solution? [SOLVED]
« Last post by VisualLab on Today at 12:48:08 pm »
Hi!   8-)

Is there any fairly simple sound solution, one can use at a (rather simple) Pascal program?

Beep and Sound didn't work for me and I found other suggestions, but they're way too old (and irrelevant), for today's Linux standards, or much complicated (eg. using sophisticated C routines etc).

Please keep in mind, that Pascal (amongst many other things) is also an educational tool and I'm in need of a rather simple solution (like the above mentioned-but no working commands Beep and Sound) and not for excellent but sophisticated C or Java like code, which are all good and well, but I'll have a really hard time, trying to demonstrate them to novice learners.

This is an operating system modeled on the old OS designed for mainframe machines. It is constantly being developed mainly to support networks, servers, etc. solutions. And it works well there. Unfortunately, Linux is not suitable for teaching or presenting multimedia solutions (audio, video, animations, fancy graphics, etc.). Yes, there are attempts to use Linux for specific multimedia applications (e.g. video editing -> DaVinci), but they are not suitable for programming education.

Please don't take this as an insult or a malicious comment. This is simply the architecture of Linux and this is how its programmers want to develop it (like many other open source projects). And users can use what is available or they can look for a different solution.

Besides, Windows multimedia solutions are not that simple either (although much better designed and operated). Unfortunately, multimedia support requires knowledge of API and/or external libraries. There are no shortcuts here.
Pages: [1] 2 3 ... 10

TinyPortal © 2005-2018