Home | Gaming | Programming | Play Online | Contact | Keyword Query
Games++ Games & Game Programming

Games++ Home
Games++ Gaming
Games++ Programming
Beta Testing Games
Free Online Games
Hints & Cheats

E-mail This Page
Add to Favorites


Web Games++

Cheat Codes
Trickster Wiki
Game Ratings
Gameboy Cheats
PlayStation Cheats
BlackBerry Games
Photoshop Tutorials
Illustrator Tutorials
ImageReady Tutorials




Xbox Programming & Development

Even tho the documentation tells you all you need to know about threads - I'm gonna put in a few words of advice here, as well as an example of nice use.

To make a thread like the DHCP thread I documented briefly in the tcp/ip section, simply do this :

CreateThread(NULL, 1024, (LPTHREAD_START_ROUTINE)SetUpNetwork, NULL, 0, NULL ); 
( 1024 = stack )

( SetUpNetwork = function pointer )

Other places I have used it - is a thread to check amount of diskspace free while debugging.

CreateThread(NULL, 128, (LPTHREAD_START_ROUTINE)FreeDiskSpaceThread, NULL, 0, NULL );

where the diskspace thread code is like :

char cfree[21];
char efree[21];

DWORD FreeDiskSpaceThread( void )
	while( 1 )
		ULARGE_INTEGER lpFreeBytesAvailable; // bytes available
		ULARGE_INTEGER lpTotalNumberOfBytes; // bytes on disk
		ULARGE_INTEGER lpTotalNumberOfFreeBytes; // free bytes on disk
		GetDiskFreeSpaceEx( "c:\\", 
		double f = (((lpTotalNumberOfFreeBytes.HighPart) * ((MAXDWORD/1024)+1)) 
			+ (lpTotalNumberOfFreeBytes.LowPart/1024));
		sprintf( cfree, "                   0 KB", f);

		GetDiskFreeSpaceEx( "e:\\", 
		f = (((lpTotalNumberOfFreeBytes.HighPart) * ((MAXDWORD/1024)+1)) 
			+ (lpTotalNumberOfFreeBytes.LowPart/1024));
		sprintf( efree, "                   0 KB", f);


Every 5th second it will update a string with the diskspace avalable, and wont bother the CPU with much load meanwhile.

Now... As you see, it's not very hard.

BUT !!!

Be careful with pointers and sharing of variables. Nothing can crash harder and weirder than threads and linked lists. And it's incredible hard to debug since you don't really get to know if its a thread or the main thread you are debugging. :-)

Copyright © 1998-2007, Games++ All rights reserved. | Privacy Policy