Thread overview
photon v0.8.0 with Events, Semaphores and Timers
photon v0.9.0 with Go-style D-flavored channels!
April 29

Photon is a minimalistic multi-threaded fiber scheduler and event loop that works transparently with traditional blocking I/O C/C++/D/Rust libraries w/o degrading performance.

This release brings in new APIs for Events, Semaphores and Timers, on all 3 supported platforms (Windows, Linux and MacOS)! For now, only fibers can use the primitives but in the next version sharing of Event or Semaphore between fibers and plain threads is planned.

--
Dmitry Olshansky
CEO @ Glow Labs
https://olshansky.me/about/

April 29

On Monday, 29 April 2024 at 20:50:24 UTC, Dmitry Olshansky wrote:

>

Photon is a minimalistic multi-threaded fiber scheduler and event loop that works transparently with traditional blocking I/O C/C++/D/Rust libraries w/o degrading performance.

This release brings in new APIs for Events, Semaphores and Timers, on all 3 supported platforms (Windows, Linux and MacOS)! For now, only fibers can use the primitives but in the next version sharing of Event or Semaphore between fibers and plain threads is planned.

Obligatory link:
https://github.com/DmitryOlshansky/photon

>

--
Dmitry Olshansky
CEO @ Glow Labs
https://olshansky.me/about/

May 03

On Monday, 29 April 2024 at 20:50:59 UTC, Dmitry Olshansky wrote:

>

On Monday, 29 April 2024 at 20:50:24 UTC, Dmitry Olshansky wrote:

>

Photon is a minimalistic multi-threaded fiber scheduler and event loop that works transparently with traditional blocking I/O C/C++/D/Rust libraries w/o degrading performance.

And now we have Channels, gentelmen. The only missing bit is select function to multiplex on a bunch of channels.

So here is example of Go-style, D-flavored channels:


import std.algorithm, std.datetime, std.range, std.stdio;
import photon;

    void first(shared Channel!string work, shared Channel!int completion) {
        delay(2.msecs);
        work.put("first #1");
        delay(2.msecs);
        work.put("first #2");
        delay(2.msecs);
        work.put("first #3");
        completion.put(1);
    }

    void second(shared Channel!string work, shared Channel!int completion) {
        delay(3.msecs);
        work.put("second #1");
        delay(3.msecs);
        work.put("second #2");
        completion.put(2);
    }

    void main() {
        startloop();
        auto jobQueue = channel!string(2);
        auto finishQueue = channel!int(1);
        go({
            first(jobQueue, finishQueue);
        });
        go({ // producer # 2
            second(jobQueue, finishQueue);
        });
        go({ // consumer
            foreach (item; jobQueue) {
                delay(1.seconds);
                writeln(item);
            }
        });
        go({ // closer
            auto completions = finishQueue.take(2).array;
            assert(completions.length == 2);
            jobQueue.close(); // all producers are done
        });
        runFibers();
    }


>

Obligatory link:
https://github.com/DmitryOlshansky/photon


Dmitry Olshansky
CEO @ Glow labs
https://olshansky.me/about/

May 10

On Friday, 3 May 2024 at 17:12:40 UTC, Dmitry Olshansky wrote:

>

On Monday, 29 April 2024 at 20:50:59 UTC, Dmitry Olshansky wrote:

>

On Monday, 29 April 2024 at 20:50:24 UTC, Dmitry Olshansky wrote:

>

Photon is a minimalistic multi-threaded fiber scheduler and event loop that works transparently with traditional blocking I/O C/C++/D/Rust libraries w/o degrading performance.

And now we have Channels, gentelmen. The only missing bit is select function to multiplex on a bunch of channels.

And the wait is over! Now there is a select function to multiplex on read side of a bunch of channels. This also fixes a bug in the poll syscall override with multiple events on posix systems

https://github.com/DmitryOlshansky/photon/blob/master/examples/select.d

module examples.select;

import std.range, std.datetime, std.stdio;

import photon;

void main() {
    startloop();
    auto first = channel!(int)(2);
    auto second = channel!(string)(1);
    go({
        delay(500.msecs);
        first.put(0);
        first.put(1);
        delay(500.msecs);
        second.put("ping");
    });
    go({
        foreach ( _; 0..3) {
            select(
                first, {
                    writefln("Got first %s", first.take(1));
                },
                second, {
                    writefln("Got second %s", second.take(1));
                }
            );
        }
    });
    runFibers();
}

>

Dmitry Olshansky
CEO @ Glow labs
https://olshansky.me/about/