Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1075 thank(s) in 852 post(s)
I'm pretty sure, from the code, that it cannot work correctly. If two players open the same chest, each grabs a (different) item, the chest has only one cWindow instance and only one m_DraggingItem, which means one of the grabbed items will be lost.
Also, multithreading is not accounted for in these classes.
Posts: 1,450
Threads: 53
Joined: Feb 2011
Thanks: 15
Given 120 thank(s) in 91 post(s)
IMO packets should be handled in a single thread instead of multiple threads, so there's no need for making it multithread safe.
You might be right about the dragging item, I only checked if it replicated the items to other clients, I didn't check whether multiple people can drag multiple items around. I'd say try it first
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1075 thank(s) in 852 post(s)
Packets used to be handled in the tick-thread only, so then it didn't matter.
Now packets are handled in the cSocketThreads and therefore *can* call these functions simultaneously from multiple threads (if there are >= 64 players on the server).
Posts: 1,450
Threads: 53
Joined: Feb 2011
Thanks: 15
Given 120 thank(s) in 91 post(s)
03-16-2012, 05:16 AM
(This post was last modified: 03-16-2012, 05:17 AM by FakeTruth.)
There's not much benefit in handling packets in separate threads though. Because so many critical sections are being locked it results in multiple threads running just as fast as a single thread.
There's probably some benefit because not all packets require critical sections to be locked, but all substantial packets do (block/entity interactions)
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1075 thank(s) in 852 post(s)
Packets are handled in the thread that receives them over network and decodes them. Having a thread specifically for handling packet would require handing them over to that thread, meaning even more critical sections etc.
Posts: 1,450
Threads: 53
Joined: Feb 2011
Thanks: 15
Given 120 thank(s) in 91 post(s)
It doesn't matter anyway, since it only becomes multiple threads when there are 64+ players on