Skip to content

Commit 2b53dc1

Browse files
Minor documentation updates.
1 parent 9300497 commit 2b53dc1

File tree

3 files changed

+27
-38
lines changed

3 files changed

+27
-38
lines changed

guides/getting-started/readme.md

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,13 @@ This guide explains how to use `async-safe` to detect thread safety violations i
44

55
## Installation
66

7-
Add this line to your application's Gemfile:
8-
9-
~~~ ruby
10-
gem 'async-safe'
11-
~~~
12-
13-
And then execute:
14-
15-
~~~ bash
16-
$ bundle install
17-
~~~
18-
19-
Or install it yourself as:
7+
Add the gem to your project:
208

219
~~~ bash
22-
$ gem install async-safe
10+
$ bundle add async-safe
2311
~~~
2412

25-
## Basic Monitoring
13+
## Usage
2614

2715
Enable monitoring in your test suite or development environment:
2816

@@ -37,7 +25,7 @@ Async::Safe.enable!
3725

3826
When a violation is detected, an `Async::Safe::ViolationError` will be raised immediately with details about the object, method, and execution contexts involved.
3927

40-
## Single-Owner Model (Default)
28+
## Single-Owner Model
4129

4230
By default, all objects are assumed to follow a **single-owner model** - they should only be accessed from one fiber/thread at a time:
4331

@@ -153,39 +141,36 @@ end
153141
Add to your test helper (e.g., `config/sus.rb` or `spec/spec_helper.rb`):
154142

155143
~~~ ruby
156-
if ENV['SAFETY_CHECK']
157-
require 'async/safe'
158-
159-
Async::Safe.enable!
160-
end
144+
require 'async/safe'
145+
146+
Async::Safe.enable!
161147
~~~
162148

163-
Then run your tests with:
149+
Then run your tests normally:
164150

165151
~~~ bash
166-
$ SAFETY_CHECK=1 bundle exec sus
152+
$ bundle exec sus
167153
~~~
168154

169-
Any thread safety violations will cause your tests to fail immediately with a clear error message showing which object was accessed incorrectly and from which execution contexts.
155+
Any thread safety violations will cause your tests to fail immediately with a clear error message showing which object was accessed incorrectly and from which fibers.
170156

171157
## How It Works
172158

173-
1. **Default Assumption**: All objects follow a single-owner model (not thread-safe)
174-
2. **TracePoint Monitoring**: Tracks which fiber/thread first accesses each object
175-
3. **Violation Detection**: Raises an exception when a different fiber/thread accesses the same object
176-
4. **Explicit Safety**: Objects/methods can be marked as thread-safe to allow concurrent access
177-
5. **Zero Overhead**: Monitoring is only active when explicitly enabled
159+
1. **Default Assumption**: All objects follow a single-owner model (not thread-safe).
160+
2. **TracePoint Monitoring**: Tracks which fiber/thread first accesses each object.
161+
3. **Violation Detection**: Raises an exception when a different fiber/thread accesses the same object.
162+
4. **Explicit Safety**: Objects/methods can be marked as thread-safe to allow concurrent access.
163+
5. **Zero Overhead**: Monitoring is only active when explicitly enabled.
178164

179165
## Use Cases
180166

181-
- **Detecting concurrency bugs** in development and testing
182-
- **Validating thread safety assumptions** in async/fiber-based code
183-
- **Finding race conditions** before they cause production issues
184-
- **Educational tool** for learning about thread safety in Ruby
167+
- **Detecting concurrency bugs** in development and testing.
168+
- **Validating thread safety assumptions** in async/fiber-based code.
169+
- **Finding race conditions** before they cause production issues.
170+
- **Educational tool** for learning about thread safety in Ruby.
185171

186172
## Performance
187173

188-
- **Zero overhead when disabled** - TracePoint is not activated
189-
- **Minimal overhead when enabled** - suitable for development/test environments
190-
- **Not recommended for production** - use only in development/testing
191-
174+
- **Zero overhead when disabled** - TracePoint is not activated.
175+
- **Minimal overhead when enabled** - suitable for development/test environments.
176+
- **Not recommended for production** - use only in development/testing.

lib/async/safe.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ module Async
1515
# By default, all objects follow a **single-owner model** - they should only be accessed
1616
# from one fiber/thread at a time. Objects or methods can be explicitly marked as
1717
# async-safe to allow concurrent access.
18+
#
19+
# Enable monitoring in your test suite to catch concurrency bugs early.
1820
module Safe
1921
# Include this module to mark specific methods as async-safe
2022
def self.included(base)

readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ This gem provides a TracePoint-based ownership tracking system that detects when
88

99
## Motivation
1010

11-
Ruby's fiber-based concurrency (via `async`) requires careful attention to object ownership. This gem helps you catch violations of the single-owner model during development, before they cause production issues.
11+
Ruby's fiber-based concurrency (via `async`) requires careful attention to object ownership. This gem helps you catch violations of the single-owner model in your test suite, preventing concurrency bugs from reaching production.
12+
13+
Enable it in your tests to get immediate feedback when objects are incorrectly shared across fibers.
1214

1315
## Usage
1416

0 commit comments

Comments
 (0)