<div dir="ltr">On 9 July 2013 07:30, Haster <span dir="ltr">&lt;<a href="mailto:haster2004@yandex.ru" target="_blank">haster2004@yandex.ru</a>&gt;</span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
first thread creates all things (connection, channels to queue and<br>
exchanges), call basic.consume and start new thread that reads messages from<br>
queue and processes them...<br></blockquote><div><br></div><div>In principle, this is fine. I would still not do it, myself: instead, I would never let a connection &quot;cross over&quot; between threads. But that&#39;s probably just superstitious of me :-)<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
But first thread can call one method, that add some binds and maybe declare<br>
new exchanges<br></blockquote><div><br></div><div>Aha! OK. Yes, that is probably the cause of the problem.<br><br></div><div>Try making sure that each thread has its own private connection to the broker. Perhaps the thread that only occasionally needs to use a connection could create it when needed, and destroy it when it is finished.<br>
<br></div><div>Connections *must* not be shared between threads[1].<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
But can it be the root of problem?<br>
I use separate channel for each used exchange and queue.<br></blockquote><div><br></div><div>There is *no* locking in librabbitmq, so *any* use of a connection across threads requires you to do the locking manually.<br></div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
And one thing for thinking. My program crashes only on HP-UX 11.31, on<br>
windows, Solaris and Linux Red Hat it works well<br></blockquote><div><br></div><div>My guess is that this is just chance. If two threads are sharing a single librabbitmq connection without any mutexing, then the bug exists on all platforms, even if it doesn&#39;t manifest deterministically.<br>
<br>Regards,<br></div><div>  Tony<br><br>[1] Unless you do some locking yourself, which is difficult and error-prone, and not something I&#39;d recommend.<br></div></div>-- <br>Tony Garnock-Jones<br><a href="mailto:tonygarnockjones@gmail.com" target="_blank">tonygarnockjones@gmail.com</a><br>
<a href="http://homepages.kcbbs.gen.nz/tonyg/" target="_blank">http://homepages.kcbbs.gen.nz/tonyg/</a>
</div></div>