in reply to Re^2: How to pass client connections to the worker threads?
in thread How to pass client connections to the worker threads?
This isn't the case in the chat server I showed, and I'm sure the purists out there, will say to use locking, etc, but that would only be needed if you were using a single shared variable being written to by multiple threads. In the chat server case, all they are doing is removing themselves from the shared array. It would be different if they could remove ANY thread from the array. Also, I was given this same comment from a threads guru, who was perplexed why locking wasn't needed, and he guessed that there is some low-level locking occurring because, in threads, the execution pointer can only be at one place at a time. BUT, KNOCK ON WOOD :-) Possibly an error may occur every million runs, but it seems to run fine for me. But add locking if you want, it won't hurt if done correctly.
I hope you are not the bearer of bad news, forewarning me of the need to lock. :-)
|
|---|