• Post Reply Bookmark Topic Watch Topic
  • New Topic

Would writing my ownlock routines for hashmap and queue reads and writes be a better solution to syn

 
joe vasher
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I were to create my own locking methods for a hashmap and queue woutl that be a safer way to handle multiple threads reading and writing to the hashmap in my main thread. example below.

then I can use my calls to lock in all my hashmap reads and writes. also, I have a thread that will be walking the hashmap and writing to each of the clients. which will (I think) eliminate the chance of 1 of the clients closing before I get to it. because it will have to obtain a lock to remove itself from the list during this process.. so it will just hang there til its turn..

good idea bad idea?

EXTRA info. Server creates a connection thread for each client. server also creates a thread to dispatch all packets to each of the client connections. (which is obtain in the above mentioned hashmap (it contains thread id, and reference to the connection class)

 
Paul Clapham
Sheriff
Posts: 21889
36
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it wouldn't be a better idea. If you don't understand synchronization (a very common problem) then the solution is to understand it. Attempting to implement your own synchronization mechanism is likely to fail. Even your proposed code includes busy-waiting, which is already a no-no.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!