Recent

Author Topic: Multi Threading  (Read 6827 times)

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: Multi Threading
« Reply #15 on: February 20, 2019, 10:24:28 pm »
You talk about cores. But when you threading Windows is calling a core of your cpu. Not Lazarus / FPC.
Do you know what threading is? It is a kind of timeslicing with a lot of processes and each process get a period time of the cpu to work on your code. Only with C or ASM you can program which core will run your proces.
Your save procedure has to start the new thread. Exactly what I did with my sample.

Be careful with variables in mainthread and new thread. You dont not interfere the data whitout critical sections.
« Last Edit: February 20, 2019, 10:27:53 pm by mangakissa »
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

wadman

  • New Member
  • *
  • Posts: 37
    • wadman's home
Re: Multi Threading
« Reply #16 on: February 21, 2019, 09:35:04 am »
You talk about cores. But when you threading Windows is calling a core of your cpu. Not Lazarus / FPC.

This is not difficult to do.
In my component, you can specify a bit mask to indicate the processor core on which the thread will work.


See AffinityMask: https://github.com/wadman/wthread


PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Multi Threading
« Reply #17 on: February 21, 2019, 09:40:13 am »
Do you know what threading is? It is a kind of timeslicing with a lot of processes and each process get a period time of the cpu to work on your code. Only with C or ASM you can program which core will run your proces.
The important point would be: without an OS or one's own OS (no matter the language). Even if you'd use C or ASM you couldn't control that on an OS (though OSes like Windows and Linux provide the ability to set the CPU affinity so that one can essentially pin a process/thread to a specific core).

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Multi Threading
« Reply #18 on: February 21, 2019, 12:29:59 pm »
It is a little bit arguable if multithreading offers any speed benefits when dealing with writing or reading. Typical HDD of a PC can only do 1 task at the time. It has an internal queue of operations, and if your app would send sequential writing tasks split in many, it would be slower than 1 bigger task, propably not very noticeably slower though. But if it's SSD, it would be able to do them simultaneously. I don't know how these translate to Rasperry PI. I can only guess that MicroSD is different tech than SSD, and i can't really find any details on it.

But in all cases there should be a data buffer on hardware which is the one apps communicate with. You can't directly access the hardware's reading or writing in that low level.
« Last Edit: February 21, 2019, 12:35:07 pm by User137 »

 

TinyPortal © 2005-2018