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.

Code Snippets / [DBP] Real multi-threading in DarkBASIC Professional

Author
Message
Mistrel
Retired Moderator
19
Years of Service
User Offline
Joined: 9th Nov 2005
Location:
Posted: 21st Apr 2008 07:52 Edited at: 21st Apr 2008 21:07
I saw Benjamin's post on multi-threading one command at a time and thought I'd complete his thought with a real multi-threading solution.

Benjamin's post can be found here:
http://forum.thegamecreators.com/?m=forum_view&t=121503&b=6

You'll need DLL 20 (Function Pointers) from IanM's Matrix1Utils plugin collection:
http://forum.thegamecreators.com/?m=forum_view&t=85209&b=18

MSDN says that this function will work only in Windows 2000 and up. However my Win32 Programmer's Reference says that it exists in Windows 95 but will only work when called from within a 32-bit program.

Sync must be on while using threads otherwise calls to DBProCore.dll may collide with another command being called internally, namely SYNC.

It's generally unsafe to use strings or any string related functions within a thread. Memory pointers to char strings should be used instead.

Mutexes (IanM's Matrix1Util DLL 3) should be used to lock access to individual commands or entire plugins to prevent collisions. It is recommended that only one command from each library be called at a time. Preferrably, only one command should be called from the entire DBP library at a time as all of its plugins share a common global structure.

My experience working with DBP and threads through the development of PureGDK has led me to the conclusion that is is generally unsafe to use threads in DBP because even when sync is on. This is because DBP either calls certain functions internally or uses the same resources as other functions which can lead to an invalid memory access crash when encountering key commands such as For/Next, Do/Loop, Sleep, Wait, etc.

Nevertheless it is possible but threads should be used at your own risk and with knowledge that it could lead to hard to random and debug crashes.

I highly recommend anyone interested in pursuing multi-threaded applications using DarkBasic Professional to look into PureGDK as an alternative. PureGDK supports not only multi-threading but can also compile thread-safe applications that use the DarkBasic Professional engine:
http://forum.thegamecreators.com/?m=forum_view&t=124255&b=8
http://www.purebasic.fr/english/viewtopic.php?t=31201



http://3dfolio.com

Login to post a reply

Server time is: 2024-11-25 02:57:17
Your offset time is: 2024-11-25 02:57:17