Jump to content
SubSpace Forum Network

Recommended Posts

Posted (edited)

I have 3 nights off tomorrow to be able to do more work.

 

 

Edit:shifted by one day. Something went wrong in my work scheduling >.>

Edited by jabjabjab
  • Replies 391
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

Posted (edited)

With the help of spidernl, the jvm crash is history.

 

A tip for those who wish to use CopyOnWriteArrayList objects, please do not do this when running multiple threads:

 

Subtracting at an thread not synced with another listening to it.

 

Edit: oh and multiple for loops reading the info across threads.

Edited by jabjabjab
Posted
Making the add/remove/loop "methods" synchronized doesn't help much. Far as I know that'd just prevent multiple threads from both adding at the same time, or both removing at the same time, etc. A thread-safe list would have to make all functions that can modify the list's contents block when one of them is 'in use'. Not that that's impossible, just sayin'.
Posted

I usually do a




List<meh> list;
lock(somequeue)
    list = somequeue.ToList();

foreach l in list
{ 
  ...
}

 

in c#. Without the handy linq functions such as ToList twould be slightly more of a hassle, but it could still be done if there aren't a lot of methods that access the list, and by keeping those methods in the same class (otherwise it gets confusing very fast). Isn't there a thread safe list in java, similar to the recently added ConcurrentBag in c# (although locking yourself woulds probably still be faster)?

Posted
I honestly dont know,. Im not out of the woods with the error yet. Only the update thread works, but the collision thread is identical, and is accessing the same info to push a method, (and i cant seem to merge both because of delay on updates) so i dunno atm wut to do about that.
Posted (edited)

class YourList extends ArrayList
{
   FancyLockingSystem mySystem;
   
   @override
   public void add()
   {
       //Do cool stuff with locks
   }
   
   @override
   public void remove()
   {
       //Do cool stuff with locks
   }
}

 

edit: You could also have a global lock and not do the locking inside the list, but instead lock the list whenever you want to access it, and unlock it whenever you're done. Then you just go like..

 

lock();

for (element : elements)

//loop

unlock();

Edited by spidernl
Posted

Holding the locks for the entire action on the array is usually a bad idea when there are a lot of concurrent threads that access the same list. If it's only occasionally this wouldn't pose a problem, but if it's accessed per frame by multiple threads I'd go for a copy of the list and do the actions on the copy (well unless the action itself also has to be blocked, then this would be fine).

 

 

The lock(); and unlock(); mentioned would have to be implemented with a mutex, semaphore or monitor, depending on what kind of locking you'd need

Posted

http://i559.photobucket.com/albums/ss31/XDreamersMS/Continuum/Aphelion/AphelionLogo4.png

http://i559.photobucket.com/albums/ss31/XDreamersMS/Continuum/Aphelion/AphelionLogo3.png

Posted

Best way is much like an IRC chat system, where all messages from a client are applied on the server and are forwarded to the others. It's not really that hard in java.

 

I wouldn't focus much on optimization or lag issues at first though, even if it takes 20kb/s per client at first, getting it to work is more important. Otherwise it might end up as a case of premature optimization.

Posted

basically, you need a socket on the server for each connected client

client sends data to the server, whether a weapon packet or a chat message

server checks to see if its legit and other stuff, then sends it to all connected clients

 

piece of cake

Posted
Don't bother with the checks until you've got the basics down, or you'll be adding more work prematurely. Have a look at getting a basic chat client working first (using the method Cheese highlighted).

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...