Bug 34271 - NSShadow throws exception when used on non-UI thread
Summary: NSShadow throws exception when used on non-UI thread
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll (show other bugs)
Version: XI 8.10
Hardware: Macintosh Mac OS
: --- enhancement
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2015-09-25 04:14 UTC by Mark Woollard
Modified: 2017-07-24 23:27 UTC (History)
3 users (show)

See Also:
Is this bug a regression?: ---
Last known good build:

Solution demonstrating defect (9.27 KB, application/zip)
2017-07-24 22:39 UTC, Larry O'Brien

Description Mark Woollard 2015-09-25 04:14:13 UTC
Accessing properties of NSShadow from background threads throws non-UI thread exception. This would appear to be same mis-conception as with NSMutableParagrahStyle (see https://bugzilla.xamarin.com/show_bug.cgi?id=28032). My understanding is that the issue with NSMutableParagraphStyle is fixed internally but am not clear as to whether its in iOS 9 release or not - we have had to hold off on this release due to other issues. What is the status with NSShadow, was that addressed at the same time or not yet fixed?
Comment 1 Sebastien Pouliot 2015-09-25 09:05:04 UTC
Sadly thread safety is not something that is well documented by Apple
for their API. It's even not uncommon to find Apple own's sample not
correctly using some API.

If the thread safety rules are not provided for an API then the 
following rules are applied:

1. UIKit is considered thread unsafe

> For the most part, use UIKit classes only from your app’s main thread.
> This is particularly true for classes derived from UIResponder or 
> that involve manipulating your app’s user interface in any way. 


2. Some exceptions are listed, globally, in this document 


3. Any other document (e.g. WWDC videos) that we can double-check
with Apple (radar) to confirm it's thread safe.

Te misuse of some API on incorrect threads can lead to hard to
find/duplicate issues inside application code. This is why XI has,
by default, added thread checks inside the (debug only) builds.

We'll review the case for NSShadow and see if we should treat it 
as thread-safe (or not) by default. At the moment this type is not
considered as thread-safe.

Note that you can totally disable this feature  globally or locally: 
Comment 2 Mark Woollard 2015-09-25 10:39:25 UTC
NSShadow can be applied to NSAttributedString/NSMutableAttributedString - the latter are thread safe and thus NSShadow would have to be to be usable. However the article you reference is very useful and I can code work around for now.
Comment 3 Larry O'Brien 2017-07-24 22:39:56 UTC
Created attachment 23769 [details]
Solution demonstrating defect

Attached solution attempts to access NSShadow from a background thread, in which case it throws (which is caught and written to console). Does it again from UI thread, in which case it doesn't throw.
Comment 4 Larry O'Brien 2017-07-24 22:40:35 UTC
Marking as "enhancement"
Comment 5 Larry O'Brien 2017-07-24 22:41:15 UTC
Thanks so much for taking the time to submit this report! I can confirm using the latest Xamarin.iOS I am able to reproduce this issue. Marking this report as CONFIRMED.

Note You need to log in before you can comment on or make changes to this bug.