Skip to content

kouweizhong/Pipes-1

 
 

Repository files navigation

Pipes

Navigation

Know what you're looking for? Try one of the links below:

Examples:

Pipes are, in my opinion, fun and easy to use. Their focus is on extensibility and ease of use, and could even be an educational tool. However, they are pretty fast too and should make your code much more maintainable!

Summary

Pipes is a concurrency abstraction designed to simplify communication and synchronisation between threads.

Concurrency is about completing multiple tasks at the same time. As more and more devices have multiple cores to exploit, parallel programming is set to become the norm! However, the tools we have now often feel unintuitive, produce convoluted systems and are hard to reason about.

Pipes aims to simplify this. Processes communicate and synchronise with each other by sending messages through (thread-safe) pipes. To illustrate:

Thread 1:

//... do some work
var message = pipe.Outlet.Receive(); //blocks until thread 2 is read to send the message
//... do more work

Thread 2:

//... do some work
pipe.Inlet.Send(message); //blocks until thread 1 is ready to receive the message
//... do more work

The real power of pipes can be better seen when pipes have multiple inlets / outlets. You can:

  • Create your own pipes easily. (For example, see if you can understand how the capacity pipe was implemented.)
  • Create your own inlets / outlets.
  • Connect multiple pipes together to form a pipe system!

This project is written in C# and is available as a Nuget Package with ID Parallel.Pipes, so it's easy to get started!

Pipes was originally inspired by CSO developed by Bernard Sufrin at Oxford University. You can learn more about CSO here. However, Pipes' goals have deviated from CSO a little - there is a much stronger focus on making it extensible - so you have the power to do whatever you need to without worrying about thread management at all!

About

An attempt at modelling concurrency using "Pipes"

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%