<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? 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> </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"><<a href="mailto:anthony.minessale@gmail.com">anthony.minessale@gmail.com</a>></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> </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. 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> ( 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 <a href="http://jira.freeswitch.org/browse/FS-3432">http://jira.freeswitch.org/browse/FS-3432</a> 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 <<a href="mailto:cmrienzo@gmail.com">cmrienzo@gmail.com</a>> wrote:<br>
> I forgot to mention that you'd have to repeat the find operation once you<br>
> get the write lock since there is a small window between the unlock and lock<br>
> where another thread may have created the item.<br>
><br>
><br>
> On Thu, Aug 18, 2011 at 6:42 AM, Christopher Rienzo <<a href="mailto:cmrienzo@gmail.com">cmrienzo@gmail.com</a>><br>
> wrote:<br>
>><br>
>> Unlock the read lock and then lock as a write lock.<br>
>><br>
>> On Aug 17, 2011 8:20 PM, "Seven Du" <<a href="mailto:dujinfang@gmail.com">dujinfang@gmail.com</a>> wrote:<br>
>><br>
>> Hi,<br>
>><br>
>><br>
>> Just wondering how to upgrade a read lock to a write lock, say I do a<br>
>> find_or_create_item_in_queue()<br>
>> switch_thread_rwlock_rdlock(lock);<br>
>> find an item from queue, if not found, create one<br>
>> switch_thread_rwlock_upgrade_to_wrlock(lock);<br>
>> write<br>
>> switch_thread_rwlock_unlock(lock);<br>
>> Thanks<br>
>> --<br>
>> Seven Du<br>
>> About: <a href="http://about.me/dujinfang" target="_blank">http://about.me/dujinfang</a><br>
>> Blog: <a href="http://www.dujinfang.com" target="_blank">http://www.dujinfang.com</a><br>
>> Proj: <a href="http://www.freeswitch.org.cn" target="_blank">http://www.freeswitch.org.cn</a><br>
>> Sent with Sparrow<br>
>><br>
>><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>
>><br>
><br>
><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>
><br>
><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>