You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guides/getting-started/readme.md
+22-37Lines changed: 22 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,25 +4,13 @@ This guide explains how to use `async-safe` to detect thread safety violations i
4
4
5
5
## Installation
6
6
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:
20
8
21
9
~~~bash
22
-
$ gem install async-safe
10
+
$ bundle add async-safe
23
11
~~~
24
12
25
-
## Basic Monitoring
13
+
## Usage
26
14
27
15
Enable monitoring in your test suite or development environment:
28
16
@@ -37,7 +25,7 @@ Async::Safe.enable!
37
25
38
26
When a violation is detected, an `Async::Safe::ViolationError` will be raised immediately with details about the object, method, and execution contexts involved.
39
27
40
-
## Single-Owner Model (Default)
28
+
## Single-Owner Model
41
29
42
30
By default, all objects are assumed to follow a **single-owner model** - they should only be accessed from one fiber/thread at a time:
43
31
@@ -153,39 +141,36 @@ end
153
141
Add to your test helper (e.g., `config/sus.rb` or `spec/spec_helper.rb`):
154
142
155
143
~~~ruby
156
-
ifENV['SAFETY_CHECK']
157
-
require'async/safe'
158
-
159
-
Async::Safe.enable!
160
-
end
144
+
require'async/safe'
145
+
146
+
Async::Safe.enable!
161
147
~~~
162
148
163
-
Then run your tests with:
149
+
Then run your tests normally:
164
150
165
151
~~~bash
166
-
$ SAFETY_CHECK=1 bundle exec sus
152
+
$ bundle exec sus
167
153
~~~
168
154
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.
170
156
171
157
## How It Works
172
158
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.
178
164
179
165
## Use Cases
180
166
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.
185
171
186
172
## Performance
187
173
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.
Copy file name to clipboardExpand all lines: readme.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,9 @@ This gem provides a TracePoint-based ownership tracking system that detects when
8
8
9
9
## Motivation
10
10
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.
0 commit comments