Re: NSTextStorage: Deadlock
Re: NSTextStorage: Deadlock
- Subject: Re: NSTextStorage: Deadlock
- From: Stefan Pantke <email@hidden>
- Date: Wed, 3 Mar 2004 16:42:44 +0100
You should ask AppKit for access to it's data structures,
since not each and any part of AppKit is thread save.
if( [consoleView lockFocusIfCanDraw] ) {
.. your code goes here
[consoleView unlockFocus];
}
Have a look at these locations:
http://developer.apple.com/documentation/Cocoa/Conceptual/
Multithreading/Tasks/appkit.html
http://developer.apple.com/documentation/Cocoa/Conceptual/
Multithreading/index.html
Furthermore, protect your own shared data structures using Locks,
since e.g. mutable objects are generally speaking not thread safe.
Stefan
___
European developer? Join the EURO cocoa/WO developer list!
Send an email to email@hidden for details.
Am 03.03.2004 um 16:04 schrieb Basil Achermann:
Hi,
I have an application with two threads, a main (GUI input) thread and a
worker thread which does some processing and occasionally updates
values in one of the application's NSTextViews. However, the app
frequently hangs if the text which is about to be replaced is currently
selected.
Here's some simplified code in order to illustrate the problem:
// - worker thread:
// - consoleView is of type NSTextView*
// - [str length] == range.length (in fact, it's even the same string
that's already there)
// - sRange.location < range.location
while (1) {
[[consoleView textStorage] replaceCharactersInRange:range
withAttributedString:str];
[consoleView setSelectedRange:sRange];
}
That program usually hangs after a fraction of a second. Here's what
happens (inverse call stack):
worker:
...
120 -[NSConcreteMutableAttributedString
replaceCharactersInRange:withAttributedString:]
120 -[NSTextStorage edited:range:changeInLength:]
120 -[NSTextStorage processEditing]
120 -[NSTextStorage
_notifyEdited:range:changeInLength:invalidatedRange:]
120 -[NSLayoutManager
textStorage:edited:range:changeInLength:invalidatedRange:]
120 -[NSLayoutManager(NSPrivate)
_fixSelectionAfterChangeInCharacterRange:changeInLength:]
120 -[NSTextView(NSSharing) setSelectedRange:affinity:stillSelecting:]
120 -[NSLayoutManager invalidateDisplayForCharacterRange:]
120 -[NSLayoutManager
glyphRangeForCharacterRange:actualCharacterRange:]
120 -[NSLayoutManager(NSPrivate)
_glyphRangeForCharacterRange:actualCharacterRange:okToFillHoles:]
120 -[NSLayoutManager(NSPrivate)
_glyphIndexForCharacterIndex:startOfRange:okToFillHoles:]
120 _NSFastFillAllGlyphHolesUpToGlyphIndex
120 -[NSRecursiveLock lock]
120 _pthread_cond_wait
120 semaphore_wait_signal_trap
120 semaphore_wait_signal_trap
main:
...
120 +[NSLayoutManager(NSPrivate) _doSomeBackgroundLayout]
120 -[NSLayoutManager(NSPrivate)
_fillLayoutHoleAtIndex:desiredNumberOfLines:]
120 -[NSConcreteTextStorage _lockForReading]
120 -[NSViewHierarchyLock lockForReadingWithExceptionHandler:]
120 _pthread_cond_wait
120 semaphore_wait_signal_trap
120 semaphore_wait_signal_trap
Deadlock?!!
The same also happens if the text is selected manually (after some
time). If sRange == range, everything works fine. Also, if there's no
selection at all. Does anybody have an idea why this happens and what
can be done about it?
TIA,
b
_______________________________________________
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.
_______________________________________________
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.