Rachel Cole

Rachel Cole

1641220693

Implementing Hazard Pointers in Rust

This time, we take a stab at implementing Hazard Pointers (https://erdani.org/publications/cuj-2004-12.pdf) in Rust. We follow along with the C++ implementation in Facebook's Folly library ( https://github.com/facebook/folly/blob/master/folly/synchronization/Hazptr.h), as well as the C++ standardization proposal (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p1121r3.pdf).

You'll learn:

  • Introduction
  • Rust for Rustaceans
  • Concurrent Memory Reclamation
  • Hazard Pointers
  • Folly's Hazard Pointer Interface
  • Delayed Reclamation
  • More Folly Interface
  • A Wild Entity Diagram Appears
  • Memory Use
  • More Folly Interface
  • Starting the Rust Code
  • Testing Out the Rust Interface
  • HazPtrHolder::load
  • HazPtrObject::retire
  • HazPtrHolder::reset
  • Unsafe Blocks in Unsafe Fns
  • Borrow Checker Prevents Misuse
  • Bad Drop Lint
  • Dropping in HazPtrDomain::retire
  • Intermission
  • Reading Folly's HazPtrDomain::retire
  • HazPtrDomain::acquire
  • HazPtrDomain::retire
  • Specifying a Deleter
  • Tests Pass?
  • Eager Reclaiming
  • Checking Reclamation Behavior
  • Update on issues we filed
  • Bugs I found
  • Can deleter alias be const?
  • impl Drop vs drop in vtable
  • Some Rust Q&A
  • Splitting up into modules
  • Support for custom domains
  • Improving static domain safety
  • Intermission
  • Aligning with Folly's HazPtrDomain
  • Aligning with Folly's HazPtrHolder
  • Aligning with Folly's HazPtrObject
  • Where we are and where next?
  • Re-visiting the interface
  • rebase: reset_protection
  • Folly changes since last time
  • rebase: hazard pointer constructors
  • rebase: irrelevant c++ commits
  • rebase: type renames
  • rebase: more irrelevant c++ commits
  • rebase: from push_retire to push_list
  • Tracking down a segfault with gdb
  • rebase: sharding the untagged list
  • rebase: track available hazard pointers
  • A quick break
  • cont'd: track available hazard pointers
  • Concurrency testing with loom
  • Writing a loom test
  • Test with two readers
  • Test dropping a non-global domain
  • Summary and next steps

You can find the code for the implementation at https://github.com/jonhoo/haphazard. 

#rust #programming #developer

What is GEEK

Buddha Community

Implementing Hazard Pointers in Rust

Serde Rust: Serialization Framework for Rust

Serde

*Serde is a framework for serializing and deserializing Rust data structures efficiently and generically.*

You may be looking for:

Serde in action

Click to show Cargo.toml. Run this code in the playground.

[dependencies]

# The core APIs, including the Serialize and Deserialize traits. Always
# required when using Serde. The "derive" feature is only required when
# using #[derive(Serialize, Deserialize)] to make Serde work with structs
# and enums defined in your crate.
serde = { version = "1.0", features = ["derive"] }

# Each data format lives in its own crate; the sample code below uses JSON
# but you may be using a different one.
serde_json = "1.0"

 

use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, Debug)]
struct Point {
    x: i32,
    y: i32,
}

fn main() {
    let point = Point { x: 1, y: 2 };

    // Convert the Point to a JSON string.
    let serialized = serde_json::to_string(&point).unwrap();

    // Prints serialized = {"x":1,"y":2}
    println!("serialized = {}", serialized);

    // Convert the JSON string back to a Point.
    let deserialized: Point = serde_json::from_str(&serialized).unwrap();

    // Prints deserialized = Point { x: 1, y: 2 }
    println!("deserialized = {:?}", deserialized);
}

Getting help

Serde is one of the most widely used Rust libraries so any place that Rustaceans congregate will be able to help you out. For chat, consider trying the #rust-questions or #rust-beginners channels of the unofficial community Discord (invite: https://discord.gg/rust-lang-community), the #rust-usage or #beginners channels of the official Rust Project Discord (invite: https://discord.gg/rust-lang), or the #general stream in Zulip. For asynchronous, consider the [rust] tag on StackOverflow, the /r/rust subreddit which has a pinned weekly easy questions post, or the Rust Discourse forum. It's acceptable to file a support issue in this repo but they tend not to get as many eyes as any of the above and may get closed without a response after some time.

Download Details:
Author: serde-rs
Source Code: https://github.com/serde-rs/serde
License: View license

#rust  #rustlang 

Rust Lang Course For Beginner In 2021: Guessing Game

 What we learn in this chapter:
- Rust number types and their default
- First exposure to #Rust modules and the std::io module to read input from the terminal
- Rust Variable Shadowing
- Rust Loop keyword
- Rust if/else
- First exposure to #Rust match keyword

=== Content:
00:00 - Intro & Setup
02:11 - The Plan
03:04 - Variable Secret
04:03 - Number Types
05:45 - Mutability recap
06:22 - Ask the user
07:45 - First intro to module std::io
08:29 - Rust naming conventions
09:22 - Read user input io:stdin().read_line(&mut guess)
12:46 - Break & Understand
14:20 - Parse string to number
17:10 - Variable Shadowing
18:46 - If / Else - You Win, You Loose
19:28 - Loop
20:38 - Match
23:19 - Random with rand
26:35 - Run it all
27:09 - Conclusion and next episode

#rust 

Rachel Cole

Rachel Cole

1641220693

Implementing Hazard Pointers in Rust

This time, we take a stab at implementing Hazard Pointers (https://erdani.org/publications/cuj-2004-12.pdf) in Rust. We follow along with the C++ implementation in Facebook's Folly library ( https://github.com/facebook/folly/blob/master/folly/synchronization/Hazptr.h), as well as the C++ standardization proposal (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p1121r3.pdf).

You'll learn:

  • Introduction
  • Rust for Rustaceans
  • Concurrent Memory Reclamation
  • Hazard Pointers
  • Folly's Hazard Pointer Interface
  • Delayed Reclamation
  • More Folly Interface
  • A Wild Entity Diagram Appears
  • Memory Use
  • More Folly Interface
  • Starting the Rust Code
  • Testing Out the Rust Interface
  • HazPtrHolder::load
  • HazPtrObject::retire
  • HazPtrHolder::reset
  • Unsafe Blocks in Unsafe Fns
  • Borrow Checker Prevents Misuse
  • Bad Drop Lint
  • Dropping in HazPtrDomain::retire
  • Intermission
  • Reading Folly's HazPtrDomain::retire
  • HazPtrDomain::acquire
  • HazPtrDomain::retire
  • Specifying a Deleter
  • Tests Pass?
  • Eager Reclaiming
  • Checking Reclamation Behavior
  • Update on issues we filed
  • Bugs I found
  • Can deleter alias be const?
  • impl Drop vs drop in vtable
  • Some Rust Q&A
  • Splitting up into modules
  • Support for custom domains
  • Improving static domain safety
  • Intermission
  • Aligning with Folly's HazPtrDomain
  • Aligning with Folly's HazPtrHolder
  • Aligning with Folly's HazPtrObject
  • Where we are and where next?
  • Re-visiting the interface
  • rebase: reset_protection
  • Folly changes since last time
  • rebase: hazard pointer constructors
  • rebase: irrelevant c++ commits
  • rebase: type renames
  • rebase: more irrelevant c++ commits
  • rebase: from push_retire to push_list
  • Tracking down a segfault with gdb
  • rebase: sharding the untagged list
  • rebase: track available hazard pointers
  • A quick break
  • cont'd: track available hazard pointers
  • Concurrency testing with loom
  • Writing a loom test
  • Test with two readers
  • Test dropping a non-global domain
  • Summary and next steps

You can find the code for the implementation at https://github.com/jonhoo/haphazard. 

#rust #programming #developer

Adonis  Kerluke

Adonis Kerluke

1624782891

Implementing Hazard Pointers in Rust

This time, we take a stab at implementing Hazard Pointers (https://erdani.org/publications/cuj-2004-12.pdf) in Rust. We follow along with the C++ implementation in Facebook’s Folly library (https://github.com/facebook/folly/blob/master/folly/synchronization/Hazptr.h), as well as the C++ standardization proposal (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p1121r3.pdf).

  • 0:00:00 Introduction
  • 0:00:37 Rust for Rustaceans
  • 0:01:00 Concurrent Memory Reclamation
  • 0:10:32 Hazard Pointers
  • 0:35:27 Folly’s Hazard Pointer Interface
  • 0:54:08 Delayed Reclamation
  • 0:58:18 More Folly Interface
  • 1:11:56 A Wild Entity Diagram Appears
  • 1:16:40 Memory Use
  • 1:21:12 More Folly Interface
  • 1:27:50 Starting the Rust Code
  • 1:35:24 Testing Out the Rust Interface
  • 1:42:32 HazPtrHolder::load
  • 2:02:15 HazPtrObject::retire
  • 2:19:43 HazPtrHolder::reset
  • 2:22:50 Unsafe Blocks in Unsafe Fns
  • 2:25:04 Borrow Checker Prevents Misuse
  • 2:27:45 Bad Drop Lint
  • 2:34:15 Dropping in HazPtrDomain::retire
  • 2:46:00 Intermission
  • 2:47:57 Reading Folly’s HazPtrDomain::retire
  • 2:59:02 HazPtrDomain::acquire
  • 3:17:32 HazPtrDomain::retire
  • 3:45:57 Specifying a Deleter
  • 4:32:26 Tests Pass?
  • 4:36:12 Eager Reclaiming
  • 4:37:32 Checking Reclamation Behavior
  • 4:52:04 Final Thoughts

You can find the code for the implementation at https://github.com/jonhoo/haphazard.

#rust #cplusplus #programming #developer

Rachel Cole

Rachel Cole

1641261305

Implementing Hazard Pointers in Rust

This tutorial, we take a stab at implementing Hazard Pointers (https://erdani.org/publications/cuj-2004-12.pdf) in Rust. We follow along with the C++ implementation in Facebook's Folly library (https://github.com/facebook/folly/blob/master/folly/synchronization/Hazptr.h), as well as the C++ standardization proposal (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p1121r3.pdf).

You'll learn:

  • Introduction
  • Rust for Rustaceans
  • Concurrent Memory Reclamation
  • Hazard Pointers
  • Folly's Hazard Pointer Interface
  • Delayed Reclamation
  • More Folly Interface
  • A Wild Entity Diagram Appears
  • Memory Use
  • More Folly Interface
  • Starting the Rust Code
  • Testing Out the Rust Interface
  • HazPtrHolder::load
  • HazPtrObject::retire
  • HazPtrHolder::reset
  • Unsafe Blocks in Unsafe Fns
  • Borrow Checker Prevents Misuse
  • Bad Drop Lint
  • Dropping in HazPtrDomain::retire
  • Intermission
  • Reading Folly's HazPtrDomain::retire
  • HazPtrDomain::acquire
  • HazPtrDomain::retire
  • Specifying a Deleter
  • Tests Pass?
  • Eager Reclaiming
  • Checking Reclamation Behavior
  • Update on issues we filed
  • Bugs I found
  • Can deleter alias be const?
  • impl Drop vs drop in vtable
  • Some Rust Q&A
  • Splitting up into modules
  • Support for custom domains
  • Improving static domain safety
  • Intermission
  • Aligning with Folly's HazPtrDomain
  • Aligning with Folly's HazPtrHolder
  • Aligning with Folly's HazPtrObject
  • Where we are and where next?
  • Re-visiting the interface
  • rebase: reset_protection
  • Folly changes since last time
  • rebase: hazard pointer constructors
  • rebase: irrelevant c++ commits
  • rebase: type renames
  • rebase: more irrelevant c++ commits
  • rebase: from push_retire to push_list
  • Tracking down a segfault with gdb
  • rebase: sharding the untagged list
  • rebase: track available hazard pointers
  • A quick break
  • cont'd: track available hazard pointers
  • Concurrency testing with loom
  • Writing a loom test
  • Test with two readers
  • Test dropping a non-global domain
  • Summary and next steps

You can find the code for the implementation at https://github.com/jonhoo/haphazard 

#rust #programming #developer