On Monday, 18 August 2025 at 15:20:14 UTC, Dmitry Olshansky wrote:
On Saturday, 16 August 2025 at 14:51:45 UTC, Dmitry Olshansky wrote:
[...]

Actually that should be 0.5.5 :)

And v0.13.0 brings new feature - offload to run compute intensive tasks outside of scheduler. Certain syscalls are automatically routed through it to avoid blocking fibers such as file I/O. Here is simple example using goOnSameThread to make sure we are actually sharing just a single eventloop thread out of many and yet it doesn't block.

import photon;

double gauss(double a, double b, double function(double) f, double step) {
    double sum = 0.0;
    for (double x = a; x < b; x += step) {
        sum += (f(x+step) + f(x))/2 * step;
    }
    return sum;
}

void boom() {
    throw new Exception("Boom!");
}

long fib(long n) {
    if (n <= 2) return 1;
    else {
return offload(() => fib(n-1)) + offload(() => fib(n-2));
    }
}

void main() {
    startloop();
    go({
        goOnSameThread({
            writeln("Blocking computation");
writeln("Integral:", gauss(0.0, 10.0, x => x*x, 1e-7));
        });
        goOnSameThread({
            writeln("Blocking computation");
writeln("Integral:", gauss(0.0, 10.0, x => x*x, 1e-7));
        });
        goOnSameThread({
            writeln("Nonblocking computation");
writeln("Integral: ", offload(() => gauss(0.0, 10.0, x => x*x, 1e-7)));
        });
        goOnSameThread({
            writeln("Nonblocking computation");
writeln("Integral: ", offload(() => gauss(0.0, 10.0, x => x*x, 1e-7)));
        });
        goOnSameThread({
writeln("Catching exception from offloaded computation");
            try {
                offload(&boom);
                assert(0);
            } catch(Exception e) {
                assert(e.msg == "Boom!");
            }
        });
        goOnSameThread({
            writeln("Recursive offload");
            writeln("Fib(15):", offload(() => fib(15)));
        });
    });
    runFibers();
}

Other photon examples:
https://github.com/DmitryOlshansky/photon/tree/master

I tried to include all the sources of photon in a application that it's cross-compiled to linux (Pi5, AArch64) and cross-linked with some C libs, and I'm seeing this:

```
2025-08-31T16:22:18.438 [error] extern(C) private ssize_t close(int fd) nothrow src/photon/linux/core.d(1150,27): Previous IR type: i32 (i32) src/photon/linux/core.d(1150,27): New IR type: i64 (i32)
```

In linux.core.d: extern(C) private ssize_t close(int fd) nothrow

but `man 2 close` is `int close(int fd)`, it's a bug?





Reply via email to