Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / DGDK.net & Thread Safety

Author
Message
jasuk70
21
Years of Service
User Offline
Joined: 3rd Dec 2002
Location: Hemel Hempstead
Posted: 8th Apr 2007 22:05
Before I embark on using threads to handle things, Does anyone know if the current version of DGDK(.net) is thread safe?

I have 3 options depending on thread safety

1) Have all worker threads use DGDK.net
2) Have all worker threads access DGDK.net via synclock (Not tried yet)
3) Have a single thread that handles everything with the DGDK.net and all the worker threads communicate with this thread to do any DGDK stuff

Jas

----
"What is this talk of 'release'? Klingons do not'release' software. It escapes leaving a bloody trail of developers and quality assurance people in its wake!"
APEXnow
Retired Moderator
21
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 8th Apr 2007 22:30 Edited at: 8th Apr 2007 22:32
To be honest, I can't answer your question because although the DGDK.NET toolkit uses .NET interop, the DGDK libraries themselves may not necessarily be thread safe. I can't garuntee whether calling one DGDK.NET function would break if another thread also tried to call something that changes the internal state flags of DGDK. Only Mike or Lee can probably answer this.

[EDIT] My only advice is that you use a mutex whenever you're going to call any of the DGDK.NET functions. Which isn't ideal I know.

Paul.


Abundance = Choice = Freedom - Scarcity = Dependancy = Control, Truth!
jasuk70
21
Years of Service
User Offline
Joined: 3rd Dec 2002
Location: Hemel Hempstead
Posted: 8th Apr 2007 22:39
Thanks,
I've started going all through my code and abstracting all the DGDK commands to use synclock. e.g.



I've tried compiling this and it seems to work fine, I've yet to try again in a thread but synclock will mutex everything although it will have a speed impact.

Jas

----
"What is this talk of 'release'? Klingons do not'release' software. It escapes leaving a bloody trail of developers and quality assurance people in its wake!"
jasuk70
21
Years of Service
User Offline
Joined: 3rd Dec 2002
Location: Hemel Hempstead
Posted: 9th Apr 2007 03:03 Edited at: 9th Apr 2007 17:53
I've just finished going through and threading my first section which is the music fade routines. I created a music fade thread object which calls the routines I had originally written, but this time I've Synclock'd the oDBMusic object so that every time the volume is changed between the two pices of music, no other thread can access the oDBMusic object. And to avoid any nasty multiple music changes happening at the same time, I created a musicLock object which is synclocked till the music fading has finished.

To show it in action visit this thread example website:

http://www.tyranntrpg.org/dgdk/thread_example/thread_example.html

[EDIT]
Here is the thread code to control the music fading:



The code that sets up the threads and the music fade routines are:



Jas

----
"What is this talk of 'release'? Klingons do not'release' software. It escapes leaving a bloody trail of developers and quality assurance people in its wake!"
APEXnow
Retired Moderator
21
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 9th Apr 2007 17:18
Excellent stuff Jasuk, so all seems to be working ok with the Mutex in place then?

Paul.


Abundance = Choice = Freedom - Scarcity = Dependancy = Control, Truth!
jasuk70
21
Years of Service
User Offline
Joined: 3rd Dec 2002
Location: Hemel Hempstead
Posted: 9th Apr 2007 18:11
Yup,
Though you do need to plan ahead if you are going to use threads to handle things, make sure you synclock every reference to the DGDK libraries. If you don't you may end up with some unexpected strangeness happening or unexpected crashes.

Now working on a message popup system that is thread based. This may take some time

Jas

----
"What is this talk of 'release'? Klingons do not'release' software. It escapes leaving a bloody trail of developers and quality assurance people in its wake!"
APEXnow
Retired Moderator
21
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 9th Apr 2007 18:20
jas, cool! Keep us posted on this because threading can be a powerful concept in .NET. Can come in useful for doing dynamic object loading during game play. I recall this being discussed in an alternate thread.

Paul.


Abundance = Choice = Freedom - Scarcity = Dependancy = Control, Truth!

Login to post a reply

Server time is: 2024-06-29 04:12:09
Your offset time is: 2024-06-29 04:12:09