<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">check out similar function that could show you how to do the locking and iterating safely<div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 13px; font-family: Monaco; color: rgb(191, 191, 191); background-color: rgb(0, 0, 0);" class="">switch_core_session_hupall_matching_var_ans</div><div class="">&nbsp;<div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Sep 15, 2015, at 7:43 AM, Ronnie Beck &lt;<a href="mailto:ronybeck@themenz.biz" class="">ronybeck@themenz.biz</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class="">Hi All,<br class=""><br class="">I have just a small question about the thread safety of the following code:<br class=""><br class="">switch_console_callback_match_t *callList = switch_core_session_findall();<br class="">for( node = callList-&gt;head; node; node = node-&gt;next )<br class="">{<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) <br class="">Checking session '%s'\n", __FUNCTION__, &nbsp;node-&gt;val);<br class="">}<br class=""><br class="">I just want to check some specific channel variables on all the active <br class="">calls on a Freeswitch server. &nbsp;However it seems to me that while <br class="">traversing the list, it is possible that "node" could be deleted by <br class="">freeswitch while my code is still using it. &nbsp;Is there some sort of <br class="">protection I should be doing in order to safely traverse the list and <br class="">investigate each session?<br class=""><br class="">I thought I could lock each session as I interrogate the session however <br class="">this doesn't protect against the situation where the "next" node is <br class="">deleted as my code switches to that node. &nbsp;In C++, if you traverse a <br class="">list with an iterator, changes to the list invalidate the iterator. &nbsp;So <br class="">one must obtain a new iterator each time the list is changed. &nbsp;&nbsp;But I <br class="">don't see how to do this with the list provided by <br class="">switch_core_session_findall().<br class=""><br class="">Any tips?<br class=""><br class="">Cheers,<br class=""><br class="">Ronnie Beck<br class=""><br class="">_________________________________________________________________________<br class="">Professional FreeSWITCH Consulting Services:<br class=""><a href="mailto:consulting@freeswitch.org" class="">consulting@freeswitch.org</a><br class="">http://www.freeswitchsolutions.com<br class=""><br class="">Official FreeSWITCH Sites<br class="">http://www.freeswitch.org<br class="">http://wiki.freeswitch.org<br class="">http://www.cluecon.com<br class=""><br class="">FreeSWITCH-dev mailing list<br class="">FreeSWITCH-dev@lists.freeswitch.org<br class="">http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev<br class="">UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-dev<br class="">http://www.freeswitch.org<br class=""></div></blockquote></div><br class=""></div></div></div></body></html>