Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
deadlock.c

 
Post new topic   Reply to topic Printable version
 View previous topic  Compiling in cygwin. Post :: Post Attention all ASSS Coders!  View next topic  
Author Message
50% Packetloss
Server Help Squatter


Age:40
Gender:Gender:Male
Joined: Sep 09 2003
Posts: 561
Location: Santa Clarita, California
Offline

PostPosted: Fri Apr 01, 2005 1:20 am    Post subject: deadlock.c Reply to topic Reply with quote

On my computer, it is impossible to shutdown ASSS properly without deadlock.c calling abort() and windows displaying a gay message about the program terminating in an odd manner. Well I narrowed the problem down to deadlock itself. When ASSS is closed (ctrl+c) the program runs a function called UnloadAllModules which in turn runs recursive_unload (it calls all of the module's entry point functions with action = MM_UNLOAD).
Here is the code from deadlock's entry point
Code: Show/Hide

if (action == MM_LOAD)
   {
      pthread_create(&thd, NULL, thread_check, NULL);
      mm->RegCallback(CB_MAINLOOP, increment, ALLARENAS);
      return MM_OK;
   }
else if (action == MM_UNLOAD)
   {
      mm->UnregCallback(CB_MAINLOOP, increment, ALLARENAS);
      pthread_cancel(thd);
      pthread_join(thd, NULL);

      return MM_OK;
   }

Deadlock is a module that makes sure that ASSS doesn't freeze up, and if it does it will terminate the program. It does this through a seperate thread of its own (the 2nd function is just so you can follow the code):
Code: Show/Hide
local void * thread_check(void *dummy)
{
   /* wait a minute initially */
   fullsleep(60 * 1000);

   for (;;)
   {
      int seen = counter;
      /* and then 10 seconds each iteration */
      fullsleep(10 * 1000);
      if (counter == seen)
      {
         fprintf(stderr, "E <deadlock> deadlock detected, aborting\n");
         abort();
      }
   }
}

local void increment(void)
{
   counter++;
}


Now, the problem IS "pthread_join(thd, NULL);" (found in the mm_unload section). I don't know a lot about threads and absolutly nothing about pthreads but I believe this function's purpose is to wait for the thread to terminate. Inorder for the thread to terminate the function has to return, but this isn't possible with an infinate for(;;) loop. So not only does it take an ass-load of time for the sleep() timers to end, but then the thread wont terminate and calls abort(). I did a crappy fix and ASSS closed perfectly (minus waiting for the sleep() timers to get done).
I could be completely wrong about all of this but it all seems logical. I tried talking to grel on his server, but he was afk and my laptop's wifi gets a lot of ploss and I get kicked out.

I think that the above is only a windows problem, because I haven't heard of any linux people complaining. I use Windows XP home edition on a Presario 905us laptop. I use the VC build of the most current version of ASSS (but I noticed the above problem with the build found on ASSS's homepage, so it's not associated with my build, which works perfecly I might add).
_________________
Current Terror Alert Level
Back to top
View users profile Send private message Add User to Ignore List Send email AIM Address
Bak
?ls -s
0 in


Age:26
Gender:Gender:Male
Joined: Jun 11 2004
Posts: 1826
Location: USA
Offline

PostPosted: Fri Apr 01, 2005 2:02 am    Post subject: Reply to topic Reply with quote

doesn't thread_join terminate the current thread?
_________________
SubSpace Discretion: A Third Generation SubSpace Client
Back to top
View users profile Send private message Add User to Ignore List AIM Address
50% Packetloss
Server Help Squatter


Age:40
Gender:Gender:Male
Joined: Sep 09 2003
Posts: 561
Location: Santa Clarita, California
Offline

PostPosted: Fri Apr 01, 2005 3:08 am    Post subject: Reply to topic Reply with quote

pthread_join's documentation
http://www.opengroup.org/onlinepubs/007908799/xsh/pthread_join.html

Here is usleep()'s documentation (called by fullsleep() ), forgot to add it to the above post.
http://www.opengroup.org/onlinepubs/007908799/xsh/usleep.html
Back to top
View users profile Send private message Add User to Ignore List Send email AIM Address
Grelminar
Creator of Asss


Joined: Feb 26 2003
Posts: 378
Offline

PostPosted: Fri Apr 01, 2005 3:38 am    Post subject: Reply to topic Reply with quote

The problem seems to be that while nanosleep (which is used to implement fullsleep on unix) is a pthread cancellation point, usleep on windows is not a cancellation point (which isn't surprising, since it's part of the windows C library, which knows nothing about the pthreads).

There are a few possible fixes: You could add "pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);" to the beginning of the deadlock thread. Or you could change the windows implementation of fullsleep (in util.c) to use the function pthreadCancelableTimedWait from the pthread-win32 library, which would make the sleep a cancellation point. I would try the first one first.
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website
50% Packetloss
Server Help Squatter


Age:40
Gender:Gender:Male
Joined: Sep 09 2003
Posts: 561
Location: Santa Clarita, California
Offline

PostPosted: Fri Apr 01, 2005 4:03 am    Post subject: Reply to topic Reply with quote

Thanks grel. I'll give it a try.

On a side note, maybe add a ToLowerStr(params) to void Cprize in playercmd.c because strstr isn't case-insensitive. But it doesn't matter.
Back to top
View users profile Send private message Add User to Ignore List Send email AIM Address
50% Packetloss
Server Help Squatter


Age:40
Gender:Gender:Male
Joined: Sep 09 2003
Posts: 561
Location: Santa Clarita, California
Offline

PostPosted: Fri Apr 01, 2005 4:20 am    Post subject: Reply to topic Reply with quote

Yah, the "pthread_setcanceltype" seems to work, still takes a bit of time to terminate (probably from all the stuff net.c has to do) but much better.
Back to top
View users profile Send private message Add User to Ignore List Send email AIM Address
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> ASSS Questions All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 45 page(s) served in previous 5 minutes.

phpBB Created this page in 0.439736 seconds : 30 queries executed (93.7%): GZIP compression disabled