• 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
how do I make NSTask thread-safe?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

how do I make NSTask thread-safe?


  • Subject: how do I make NSTask thread-safe?
  • From: Alex Reynolds <email@hidden>
  • Date: Wed, 27 Nov 2002 13:10:37 -0500

I have a problem where a program is freezing not on running an NSTask but when the NSTask reaches the method -waitUntilExit.

My code waits for a notification that disks have been ejected from NSWorkspace.

Then the code acquires a NSConditionLock, loops through a scan of the remaining mounted disks against an internal NSMutableArray, and if one is found to be in the mutable array but not "on the Desktop", a NSTask-based method is called to unmount a hidden disk.

Once the hidden disk is ejected, the conditional lock is released and the loop goes through its remaining iterations, until another mismatch is found and the NSTask is called again.

Something like this:

for (i = 0; i < number of disks in internal table; i++)
[acquireConditionalLock]
[searchInternalDiskTableAgainstNSWorkspaceMountedVolumes];
if (mismatchFound)
[callNSTaskToUnmountHiddenDiskThatIsLeftBehind];
[releaseConditionalLock]

But what is happening is that the program hangs up on the portion of code in "callNSTaskToUnmountHiddenDiskThatIsLeftBehind" where I run [NSTask waitUntilExit].

I've been reading the multithreading documentation at:

Developer/Documentation/Cocoa/TasksAndConcepts/ProgrammingTopics/ Multithreading/

which says that NSTask is not thread-safe.

I wrapped the "callNSTaskToUnmountHiddenDiskThatIsLeftBehind" code in an NSLock, but this did not help. E.g.:

NSLock *unmountImageLock = [[NSLock alloc] init];
[unmountImageLock lock];

// hdiutil detach /dev/diskN
NSTask *hdiutilPrimaryDiskTask = [[NSTask alloc] init];

[hdiutilPrimaryDiskTask setLaunchPath:@"/usr/bin/hdiutil"];

// set arguments
[hdiutilPrimaryDiskTask setArguments:[NSArray arrayWithObjects:@"detach",imageStubPath,nil]];
[hdiutilPrimaryDiskTask launch];
[hdiutilPrimaryDiskTask waitUntilExit];

[unmountImageLock unlock];

Does anyone know how to make NSTask work with one thread at a time?

-Alex
_______________________________________________
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: How to know if a modem is installed?
  • Next by Date: NSTextContainer subclass question
  • Previous by thread: Re: How to know if a modem is installed?
  • Next by thread: NSTextContainer subclass question
  • Index(es):
    • Date
    • Thread