• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Deadlock on application quit -- Control enable/disable
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Deadlock on application quit -- Control enable/disable


  • Subject: Deadlock on application quit -- Control enable/disable
  • From: Eric Seidel <email@hidden>
  • Date: Fri, 15 Feb 2002 00:44:00 +0100

When my application exits, I have to kill all the threads (just one) and write out all the data.

Sounds simple enough.

So I tell the thread to exit, and then it enter's it's standard thread exited code:

- (void)threadExited:(id)ignored
{
if (appTerminating)
return;
if (!threadRunning)
printf("thread not running! very strange!\n");

threadRunning = NO;

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

// make sure we don't draw while we're doing this
printf("Caught thread exiting.\nCleaning up memory and writing databases\n");

//[transfersTable lockFocus];
deleteAllConnectionRecords(STATS);
//[transfersTable unlockFocus];

clientThread = nil;

if(STATS.Resumes != NULL && STATS.Resumes != 0)
STATS.Resumes->writeToDisk(STATS.setDisplayedFileSystemChange);

if(STATS.Shares != NULL && STATS.Shares != 0)
STATS.Shares->writeToDisk(STATS.setDisplayedFileSystemChange);

[[transfersTable superview] setNeedsDisplay: YES];

[toggleLoginButton setTitle:@"Login"];
if (!appTerminating && [toggleLoginButton canDraw])
[toggleLoginButton setEnabled:YES];

if (notDone)
setServerStatus("Error, check log. (under Window menu)");
else
setServerStatus("Disconnected");

[pool release];
}


That gets called right when the thread exists... which is right about the same time that my application terminating method gets called:

- (void)applicationWillTerminate:(NSNotification*)aNotification
{
appTerminating = YES; // prevents thread_exited from running.

printf("Application Will Terminate method called\n");

/* no need to clean up, but we shoudl write to disk if we are still running and if we can. */
if (threadRunning)
{
threadRunning = NO;
if(STATS.Resumes != NULL && STATS.Resumes != 0)
STATS.Resumes->writeToDisk(STATS.setDisplayedFileSystemChange);

if(STATS.Shares != NULL && STATS.Shares != 0)
STATS.Shares->writeToDisk(STATS.setDisplayedFileSystemChange);
}

printf("done with application will terminate\n");
}



THE problem is, that often, threadExited: deadlocks when trying to execute

if (!appTerminating && [toggleLoginButton canDraw])
[toggleLoginButton setEnabled:YES];

(notice how many times I try to check to make sure that it won't!)

both threads sit in a waiting state.

I ofcourse don't want to enclose this in a do-only-if-we-can-aquire-the-focus-lock... or however the command is called, because then there would be a chance that the button did not get re-enabled when the thread normally exits... (which happens if they logout without quiting the app)

Any thoughts?

Any ideas why it might be sitting in deadlock waiting to get the lock on the button, which has probably been deleted from the app by the time this is executing...?

Thanks again to all of your for your comments on my SIGNAL problem.

-eric
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: 4 notifications for visual Apps
  • Next by Date: Re: PB Save As ASCII?
  • Previous by thread: Re: 4 notifications for visual Apps
  • Next by thread: How do you run scripts within Cocoa Apps?
  • Index(es):
    • Date
    • Thread