<div dir="ltr">Thanks very much Daniel and Alex,<div><br></div><div>I switched to the atomic increase ("<span style="font-family:arial,sans-serif;font-size:12.666666984558105px">$var(x) = $shtinc(a=>x);</span>"), </div>

<div><br></div><div>My attempt to get automatic expiration and resetting of values to 0 by doing "<span style="font-family:arial,sans-serif;font-size:12.666666984558105px">modparam("htable", "htable", "message_counters=>size=10;</span><span style="font-family:arial,sans-serif;font-size:12.666666984558105px">autoexpire=10;initval=0;</span><span style="font-family:arial,sans-serif;font-size:12.666666984558105px">updateexpire=0;")</span>" was not successful (values persisted), but I could achieve it by having a timer route block (using "rtimer") that expires every 10 second and calling "sht_rm_name_re("message_counters=>.*");" inside it (in case that it may help people who will get into the same issue later)</div>

<div><br></div><div><br></div><div>All the best,</div><div>Alireza</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Aug 13, 2014 at 10:58 AM, Daniel-Constantin Mierla <span dir="ltr"><<a href="mailto:miconda@gmail.com" target="_blank">miconda@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class=""><br>
On 13/08/14 16:24, Alex Balashov wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 08/13/2014 10:21 AM, AliReza Khoshgoftar Monfared wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Another concern is that, if I specify a number of child processes in my<br>
config (e.g. children=4), then will it be safe to increment the hash<br>
table entries in the route block upon receipt of messages? i.e will the<br>
table entries that reside in the shared memory be precise? or do I need<br>
to lock/unlock them while updating?<br>
</blockquote>
<br>
htable operations are thread-safe, as implemented under the hood. You do not explicitly need to lock anything.<br>
<br>
</blockquote></div>
While that is true for htable (direct) operations, one should be careful when using hash table items in expressions.<br>
<br>
So:<br>
<br>
- next is an atomic increment of $sht(a=>x)<br>
<br>
$var(x) = $shtinc(a=>x);<br>
<br>
- but next might rise races:<br>
<br>
$sht(a=>x) = $sht(a=>x) + 1;<br>
<br>
because first the value is read, an add expression is evaluated and then the item in hash table is set to new value. During the evaluation of the expression, the current process can lose CPU, and another process can update the item. So you can make it safer with:<br>


<br>
sht_lock("a=>x");<br>
$sht(a=>x) = $sht(a=>x) + 1;<br>
sht_unlock("a=>x");<br>
<br>
Cheers,<br>
Daniel<div class="im HOEnZb"><br>
<br>
-- <br>
Daniel-Constantin Mierla<br>
<a href="http://twitter.com/#!/miconda" target="_blank">http://twitter.com/#!/miconda</a> - <a href="http://www.linkedin.com/in/miconda" target="_blank">http://www.linkedin.com/in/<u></u>miconda</a><br>
Next Kamailio Advanced Trainings 2014 - <a href="http://www.asipto.com" target="_blank">http://www.asipto.com</a><br>
Sep 22-25, Berlin, Germany ::: Oct 15-17, San Francisco, USA<br>
<br>
<br></div><div class="HOEnZb"><div class="h5">
______________________________<u></u>_________________<br>
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list<br>
<a href="mailto:sr-users@lists.sip-router.org" target="_blank">sr-users@lists.sip-router.org</a><br>
<a href="http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users" target="_blank">http://lists.sip-router.org/<u></u>cgi-bin/mailman/listinfo/sr-<u></u>users</a><br>
</div></div></blockquote></div><br></div>