项目作者: mersinvald

项目描述 :
An example implementatation of synchronized queue for inter-process communication in shared memory
高级语言: Rust
项目地址: git://github.com/mersinvald/rust_shm_ipc.git
创建时间: 2017-02-17T16:18:06Z
项目社区:https://github.com/mersinvald/rust_shm_ipc

开源协议:

下载


SHM IPC example in Rust

Build Status

This is an example implementatation of synchronized queue for inter-process communication in shared memory
for UNIX POSIX-complaint operating systems.

Motivation is to try out rust in unix systems programming

Goals:

  • Safe IPC queue implementation
  • Rusty wrappers for pthread sync primitives

Non-goals:

  • Fast IPC queue
  • Production-ready code
  • Full-featured wrappers

Library support

Currently this example relies on master branch of rust-lang/libc because of
https://github.com/rust-lang/libc/commit/532d80cdc139ea56351e21685bcfba2d3c93e34d

Required bindings will be availible in version 0.2.21

Usage example

  1. fn child(queue: Shm<Queue<i32>>) {
  2. let pid = process::pid();
  3. queue.push(pid).unwrap()
  4. }
  5. fn main() {
  6. // Create new queue in shm
  7. let queue = Shm::new(Queue::pshared())
  8. .unwrap();
  9. // Spawn processes
  10. for _ in 0..10 {
  11. process::spawn(|| {
  12. child(queue.clone());
  13. }).unwrap();
  14. }
  15. while let Ok(Some(pid)) = queue.timed_pop(Duration::from_millis(10)) {
  16. println!("PID {}", pid);
  17. }
  18. }