<div dir="ltr"><p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;color:rgb(69,69,69)">Hi everyone!</p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;color:rgb(69,69,69);min-height:14px"><br></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;color:rgb(69,69,69)">One of the challenges we faced on Blink was to make Mosh work multithreaded. These were the basic changes made:</p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;color:rgb(69,69,69);min-height:14px"><br></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;color:rgb(69,69,69)">* Compressor - A shared compressor between threads makes sense, but the problem is the internal buffer inside the class needs to be per thread.</p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;color:rgb(69,69,69);min-height:14px"><br></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;color:rgb(69,69,69)">* Select - There is one client instanced per thread, the problem is that handle_signal (for that thread), would come from nowhere and needs to figure out for what.</p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;color:rgb(69,69,69);min-height:14px"><br></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;color:rgb(69,69,69)">* millis_cache on <a href="http://timestamp.cc"><span style="color:rgb(228,175,9)">timestamp.cc</span></a> - I thought this was gonna be fine, and the client actually works for a long time. But if you fully close and then reopen a new one, obviously the millis_cache will be all wrong.</p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;color:rgb(69,69,69);min-height:14px"><br></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;color:rgb(69,69,69)">For stability testing, and making sure these were the only ones, I used pthread on the first two and __thread on the last one (there is no function to change that). It is working fine, so that’s all that is required to make Mosh multithreaded.</p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;color:rgb(69,69,69);min-height:14px"><br></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;color:rgb(69,69,69)">On the solutions side of things:</p>
<ul>
<li style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;color:rgb(69,69,69)">pthread I do not think it is a good option due to platform reasons.</li>
<li style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;color:rgb(69,69,69)">Adding __thread on all the statics would be a suitable solution but not all the compilers and architectures might support it, it could just be a compiling option. </li>
<li style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;color:rgb(69,69,69)">Removing singletons could be the second option. On the Compressor, maybe the NetworkTransport could have one compressor but there are strange ties between object, and also not very clear on the Select and millis_cache case.</li>
</ul>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;color:rgb(69,69,69);min-height:14px"><br></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;color:rgb(69,69,69)">Please let me know what you think, as maybe this will complicate more than it would add and it isn’t of general appeal to have on the main branch. Someone with more expertise might have more feedback too on possible ways. I’m glad to work on any of them.</p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;color:rgb(69,69,69);min-height:14px"><br></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;color:rgb(69,69,69)">Thanks!!</p><div><br></div></div>