question

kavehrahimi-5744 avatar image
0 Votes"
kavehrahimi-5744 asked BarrySchwarz-8780 commented

Femtoseconds delay in c++

Hi , I am searching for a delay function that its duration is one femtosecond. How can I write my code?
Please explain completely by example.
Thanks

c++
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

You have a personal device with a timer that has femtosecond resolution? Would the instruction to initiate the delay terminate before the femtosecond had elapsed?

0 Votes 0 ·

No , my delay function I said is a part of my code. That's not a hardware device.

0 Votes 0 ·

The function may be part of your code but it has to run on your hardware and operating system (the environment). Most delay functions take advantage of the the environment's ability to signal when the desired interval has elapsed. Even if you chose to create a spin loop and test the system clock each iteration, you would still need the value you are checking to have femtosecond or better resolution .

0 Votes 0 ·

1 Answer

IgorTandetnik-1300 avatar image
1 Vote"
IgorTandetnik-1300 answered

You can't. Consider: a typical modern CPU runs at about 3-4 GHz. This means a single machine instruction takes some 2*10^-10s to execute. You want something that's five orders of magnitude more precise (1 femtosecond = 10^-15 seconds). Your computer simply doesn't have any kind of clock running anywhere near this frequency. You'd need very specialized hardware to measure time with such precision.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.