www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - photon v0.8.0 with Events, Semaphores and Timers

reply Dmitry Olshansky <dmitry.olsh gmail.com> writes:
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://glow-labs.pro)
https://olshansky.me/about/
Apr 29
parent reply Dmitry Olshansky <dmitry.olsh gmail.com> writes:
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://glow-labs.pro)
 https://olshansky.me/about/
Apr 29
parent reply Dmitry Olshansky <dmitry.olsh gmail.com> writes:
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: ```d import std.algorithm, std.datetime, std.range, std.stdio; import photon; void first(shared Channel!string work, shared Channel!int completion) { delay(2.msecs); delay(2.msecs); delay(2.msecs); completion.put(1); } void second(shared Channel!string work, shared Channel!int completion) { delay(3.msecs); delay(3.msecs); completion.put(2); } void main() { startloop(); auto jobQueue = channel!string(2); auto finishQueue = channel!int(1); go({ first(jobQueue, finishQueue); }); 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://glow-labs.pro) https://olshansky.me/about/
May 03
parent Dmitry Olshansky <dmitry.olsh gmail.com> writes:
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 ```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://glow-labs.pro)
 https://olshansky.me/about/
May 10