Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

My XNA project currently uses one ContentManager instance, and one dedicated background thread for loading all content.

I wonder, would it be safe to have multiple ContentManager instances, each in it's own dedicated thread, loading different content at the same time?

I'm prompted to ask this question because this article makes the following statement:

If there are two textures created at the same time on different threads, they will clobber the other and you will end up with some garbage in the textures.

I think that what the author is saying here, is that if I access one ContentManager simultaneously on two threads, I'll get garbage. But what if I have separate ContentManager instances for each thread?

If no-one knows the answer already from experience, I'll go ahead and try it and see what happens.

share|improve this question
    
It's a good question, but If no-one knows the answer already from experience, I'll go ahead and try it and see what happens. should be done before asking this question. –  Austin Brunkhorst Nov 2 '12 at 3:22
2  
Thanks @AustinBrunkhorst, I don't disagree, but this does make a nice place to share the answer once I find it don't you think? –  Boinst Nov 2 '12 at 4:35
1  
The author of your linked article seems to be stating that creating textures is not thread-safe in XNA (ie: irrespective of how you use ContentManager). I have never heard this before - and I can't find anyone else making the same claim. But I have seen many people saying that it is safe, including original XNA team lead Shawn Hargreaves, in MikeBMcL's link (and several other places). –  Andrew Russell Nov 2 '12 at 11:35

2 Answers 2

up vote 4 down vote accepted

It should be fine. See: http://xboxforums.create.msdn.com/forums/t/18034.aspx .

I disagree with the comment - "If no-one knows the answer already from experience, I'll go ahead and try it and see what happens. should be done before asking this question." - as regards this particular question since threading problems are often hard to tease out so it's, to me at least, better to ask since you might test, find nothing, go live, and have a lot of crash reports start coming in because of some small architectural difference on a particular chipset that exposes a race condition your testing on other chipsets missed.

share|improve this answer
    
Holy awesomeness, the thread you linked to I think has very relevant discussion, I'll have a good read through before accepting the answer, thank you! –  Boinst Nov 2 '12 at 5:01

I'm using this library to load content in background with no problems.

http://contenttracker.codeplex.com/

It let's unload individual assets, force file read (for editors), know the relationship among assets... it's worth

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.