Even if that works, what happens when two threads that have a read lock attempt to switch to a write lock simultaneously?  How does the thread know it got the write lock first and the data is unchanged?<br><br><br><br><div class="gmail_quote">
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 class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
can&#39;t you just write lock it right away?<br>
<div><div></div><div class="h5"><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&#39;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, &quot;Seven Du&quot; &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:  <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></div><div class="h5"><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></blockquote></div><br>