[ENet-discuss] Multithreading: dealing with enet_host_service blocking

Beau Albiston albiston at cynergy.com
Tue Sep 14 19:58:42 PDT 2010


  Actually, that was how I had it setup initially. However, IIRC (as 
it's been awhile), the serving host suffered performance problems (race 
conditions) as the client count grew. I was able to get the best 
performance with the modifications I made since it relies purely on 
waiting for event objects. It should be possible to come up with a setup 
that is cross-platform (using pthreads perhaps?). I also target OS X, so 
that is important to me.

Thanks!
-Beau

On 9/14/10 2:09 AM, Benoit Germain wrote:
>
> Hello,
>
> Why don’t you just call enet_host_service with some small timeout? The 
> function will return even when there is nothing to process and you can 
> send all you want. Admittedly this may cause some delay up to the 
> timeout you specified, but this seems to work well enough for me.
>
> Benoit.
>
> *De :* enet-discuss-bounces at cubik.org 
> [mailto:enet-discuss-bounces at cubik.org] *De la part de* Beau Albiston
> *Envoyé :* lundi 13 septembre 2010 23:13
> *À :* enet-discuss at cubik.org
> *Objet :* [ENet-discuss] Multithreading: dealing with 
> enet_host_service blocking
>
> Hello All,
>
> I’m particularly interested in how people are dealing with the 
> enet_host_service blocking on receive when you have things to send…
>
> I have solved this problem already, but was curious as to how others 
> have solved the same problem. My solution involved making (only for 
> Win32 in my case) modifications to the enet_socket_wait function to 
> allow waiting on socket send and receive, as well as a “cancel wait” 
> event object (using WSAEventSelect, and WSAWaitForMultipleObjects). I 
> then added an additional function (enet_socket_cancel_wait) that 
> signals the “cancel wait” event object and wakes the network thread. 
> From there, the enet_host_service function returns with a timeout 
> event from which I can then pluck a queued send command from my queue 
> (using lock-free queues). So, my main thread queues a send command and 
> then calls enet_socket_cancel_wait to wake the network thread (in case 
> it is waiting on recv) to process the send command.
>
> (Lee, if you’re interested in the changes, I can send them to you.)
>
> Thanks,
>
> -Beau
>
>
> _______________________________________________
> ENet-discuss mailing list
> ENet-discuss at cubik.org
> http://lists.cubik.org/mailman/listinfo/enet-discuss



More information about the ENet-discuss mailing list