<div>
            <div><span><br></span>
                
                <p style="color: #a0a0a0;">On Friday, August 19, 2011 at 1:35 AM, Christopher Rienzo wrote:</p>
                <blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-left:0px;padding-left:10px;">
                    <span><div><div>Even if that works, what happens when two threads that have a read lock attempt to switch to a write lock simultaneously?&nbsp; How does the thread know it got the write lock first and the data is unchanged?<br><br><br></div></div></span></blockquote><div>maybe try_get_write_lock and let the latter one failed ? no idea. see following comments.</div><div>&nbsp;</div><blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-left:0px;padding-left:10px;"><span><div><div><br><div>
On Thu, Aug 18, 2011 at 12:20 PM, Anthony Minessale <span dir="ltr">&lt;<a href="mailto:anthony.minessale@gmail.com">anthony.minessale@gmail.com</a>&gt;</span> wrote:<br><blockquote type="cite"><div>
can't you just write lock it right away?<br></div></blockquote></div></div></div></span></blockquote><div><br></div><div>&nbsp;</div><div>I think there's a potential race when two threads try to find and launch new listeners respectively. So I try to add a find_or_create_listener() to avoid race. &nbsp;It usually only need to create once unless 1) at the first time, 2) the node is broken so need a reconnect</div><div><br></div><div><br></div><div><div><a href="http://pastebin.freeswitch.org/17091">http://pastebin.freeswitch.org/17091</a>&nbsp;( I moved some codes, so just look for find_or_create_listener() )</div></div><div><br></div><div><br></div><div>So my concern is - isn't it expensive for a write lock than a read lock? Do you have other suggestions on this? or should I just get a write lock on not found and simply find again?</div><div><br></div><div>I'm not sure if this is related to&nbsp;<a href="http://jira.freeswitch.org/browse/FS-3432">http://jira.freeswitch.org/browse/FS-3432</a>&nbsp; but want to fix the potential race first.</div><div><br></div><div>let me know if you want to attach the patch to jira but it's not the final patch still need some further work.</div><div><br></div><div>Thanks.</div><blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-left:0px;padding-left:10px;"><span><div><div><div><blockquote type="cite"><div>
<div><div><br>
On Thu, Aug 18, 2011 at 7:19 AM, Christopher Rienzo &lt;<a href="mailto:cmrienzo@gmail.com">cmrienzo@gmail.com</a>&gt; wrote:<br>
&gt; I forgot to mention that you'd have to repeat the find operation once you<br>
&gt; get the write lock since there is a small window between the unlock and lock<br>
&gt; where another thread may have created the item.<br>
&gt;<br>
&gt;<br>
&gt; On Thu, Aug 18, 2011 at 6:42 AM, Christopher Rienzo &lt;<a href="mailto:cmrienzo@gmail.com">cmrienzo@gmail.com</a>&gt;<br>
&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Unlock the read lock and then lock as a write lock.<br>
&gt;&gt;<br>
&gt;&gt; On Aug 17, 2011 8:20 PM, "Seven Du" &lt;<a href="mailto:dujinfang@gmail.com">dujinfang@gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Hi,<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; Just wondering how to upgrade a read lock to a write lock, say I do a<br>
&gt;&gt; find_or_create_item_in_queue()<br>
&gt;&gt; switch_thread_rwlock_rdlock(lock);<br>
&gt;&gt; find an item from queue, if not found, create one<br>
&gt;&gt; switch_thread_rwlock_upgrade_to_wrlock(lock);<br>
&gt;&gt; write<br>
&gt;&gt; switch_thread_rwlock_unlock(lock);<br>
&gt;&gt; Thanks<br>
&gt;&gt; --<br>
&gt;&gt; Seven Du<br>
&gt;&gt; About: <a href="http://about.me/dujinfang" target="_blank">http://about.me/dujinfang</a><br>
&gt;&gt; Blog: <a href="http://www.dujinfang.com" target="_blank">http://www.dujinfang.com</a><br>
&gt;&gt; Proj: &nbsp;<a href="http://www.freeswitch.org.cn" target="_blank">http://www.freeswitch.org.cn</a><br>
&gt;&gt; Sent with Sparrow<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; Join us at ClueCon 2011, Aug 9-11, Chicago<br>
&gt;&gt; <a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a> 877-7-4ACLUE<br>
&gt;&gt;<br>
&gt;&gt; FreeSWITCH-dev mailing list<br>
&gt;&gt; <a href="mailto:FreeSWITCH-dev@lists.freeswitch.org">FreeSWITCH-dev@lists.freeswitch.org</a><br>
&gt;&gt; <a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev</a><br>
&gt;&gt; UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-dev" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-dev</a><br>
&gt;&gt; <a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
&gt;&gt;<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Join us at ClueCon 2011, Aug 9-11, Chicago<br>
&gt; <a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a> 877-7-4ACLUE<br>
&gt;<br>
&gt; FreeSWITCH-dev mailing list<br>
&gt; <a href="mailto:FreeSWITCH-dev@lists.freeswitch.org">FreeSWITCH-dev@lists.freeswitch.org</a><br>
&gt; <a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev</a><br>
&gt; UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-dev" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-dev</a><br>
&gt; <a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
&gt;<br>
&gt;<br>
<br>
<br>
<br>
</div></div>--<br>
Anthony Minessale II<br>
<br>
FreeSWITCH <a href="http://www.freeswitch.org/" target="_blank">http://www.freeswitch.org/</a><br>
ClueCon <a href="http://www.cluecon.com/" target="_blank">http://www.cluecon.com/</a><br>
Twitter: <a href="http://twitter.com/FreeSWITCH_wire" target="_blank">http://twitter.com/FreeSWITCH_wire</a><br>
<br>
AIM: anthm<br>
<a href="mailto:MSN%3Aanthony_minessale@hotmail.com">MSN:anthony_minessale@hotmail.com</a><br>
GTALK/JABBER/<a href="mailto:PAYPAL%3Aanthony.minessale@gmail.com">PAYPAL:anthony.minessale@gmail.com</a><br>
IRC: <a href="http://irc.freenode.net" target="_blank">irc.freenode.net</a> #freeswitch<br>
<br>
FreeSWITCH Developer Conference<br>
<a href="mailto:sip%3A888@conference.freeswitch.org">sip:888@conference.freeswitch.org</a><br>
<a href="mailto:googletalk%3Aconf%2B888@conference.freeswitch.org">googletalk:conf+888@conference.freeswitch.org</a><br>
pstn:<a href="tel:%2B19193869900" value="+19193869900">+19193869900</a><br>
<div><div><br>
_______________________________________________<br>
Join us at ClueCon 2011, Aug 9-11, Chicago<br>
<a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a> 877-7-4ACLUE<br>
<br>
FreeSWITCH-dev mailing list<br>
<a href="mailto:FreeSWITCH-dev@lists.freeswitch.org">FreeSWITCH-dev@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-dev" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-dev</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
</div></div></div></blockquote></div><br>
</div><div>_______________________________________________<br>Join us at ClueCon 2011, Aug 9-11, Chicago<br><a href="http://www.cluecon.com">http://www.cluecon.com</a> 877-7-4ACLUE<br><br>FreeSWITCH-dev mailing list<br><a href="mailto:FreeSWITCH-dev@lists.freeswitch.org">FreeSWITCH-dev@lists.freeswitch.org</a><br><a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev">http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev</a><br>UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-dev">http://lists.freeswitch.org/mailman/options/freeswitch-dev</a><br><a href="http://www.freeswitch.org">http://www.freeswitch.org</a><br></div></div></span>
                
                
                
                
                </blockquote>
                
                <div>
                    <br>
                </div>
            </div>
        </div>