From 81e779a0191c824f3e4c0df23736bdadb052ac7c Mon Sep 17 00:00:00 2001
From: Xavier Noria <fxn@hashref.com>
Date: Sun, 7 Feb 2010 11:22:25 +0100
Subject: AS guide: documents Module#synchronize

---
 .../source/active_support_core_extensions.textile  | 24 ++++++++++++++++++++++
 1 file changed, 24 insertions(+)

(limited to 'railties/guides/source/active_support_core_extensions.textile')

diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index ed2b41af86..4f7c0c56e2 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -791,6 +791,30 @@ WARNING: This method is exact if running under Ruby 1.9. In previous versions it
 
 NOTE: Defined in +active_support/core_ext/module/introspection.rb+.
 
+h4. Synchronization
+
+The +synchronize+ macro declares a method to be synchronized:
+
+<ruby>
+class Counter
+  @@mutex = Mutex.new
+  attr_reader :value
+
+  def initialize
+    @value = 0
+  end
+
+  def incr
+    @value += 1 # non-atomic
+  end
+  synchronize :incr, :with => '@@mutex'
+end
+</ruby>
+
+The method receives the name of an action, and a +:with+ option with code. The code is evaluated in the context of the receiver each time the method is invoked, and it should evaluate to a +Mutex+ instance or any other object that responds to +synchronize+ and accepts a block. 
+
+NOTE: Defined in +active_support/core_ext/module/synchronization.rb+.
+
 h3. Extensions to +Class+
 
 h4. Class Attributes
-- 
cgit v1.2.3

