Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

vaneger

Newbie MultiThreading problems

This topic is 5531 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i have this code :::
  
#include<iostream.h>
#include<MTQKSRT.h>
void main (void)
{
	threadCount = 0;
	threadHandles[300];
	threadIDs[300];
	apvector<int> mlist(10);
	mlist[0] = 34 ;
	mlist[1] = 4;
	mlist[2] = 54;
	mlist[3] = 65;
	mlist[4] = 23;
	mlist[5] = 1;
	mlist[6] = 45;
	mlist[7] = 87;
	mlist[8] = 67;
	mlist[9] = 12;
    threadHandles[threadCount] = CreateThread(NULL,0,MTQuickSort((LPVOID)1,mlist,0,mlist.length()-1),(LPVOID)threadCount,0,&threadIDs[threadCount]);		
}

  

  
#include<apvector.h>
#include<windows.h>
#include<windowsx.h>
#include<winbase.h>
#include<stdlib.h>
#include<stdarg.h>
#include<stdio.h>
#include<math.h>
#include<io.h>
#include<fcntl.h>

HANDLE threadHandles[];
DWORD threadIDs[];
int threadCount; //ini to zero

template <class type>
DWORD WINAPI MTQuickSort(LPVOID data,apvector<type> &list, int start, int end)
{
	if (start >= end) // base case (list is sorted)

		return ((DWORD)0);
	// choose a pivot point	

	int pivot = list[(start+end)/2];
	int leftbound = start;
	int rightbound = end;
	while (leftbound <= rightbound)
	{		
		// find first element that is greater than pivot on left side

		while ((leftbound < end) && (list[leftbound] < pivot))
			leftbound++;
		// find first element that is smaller than pivot on right side

		while ((rightbound > start) && (list[rightbound] > pivot))
		   	rightbound--;	
		// swap if indexes haven''t crossed

			if (leftbound <= rightbound)
			{
				int temp = list[leftbound];
				list[leftbound] = list[rightbound];
				list[rightbound] = temp;
				leftbound++;
				rightbound--;
		}
	}
	threadCount++;
	threadHandles[threadCount] = CreateThread(NULL,0,&MTQuickSort(data,list, start, rightbound),(LPVOID)threadCount,0,&threadIDs[threadCount]);
	// sort left

	threadCount++;
	threadHandles[threadCount] = CreateThread(NULL,0,MTQuickSort(data,list, leftbound, end),(LPVOID)threadCount,0,&threadIDs[threadCount]);
	// sort right

	return ((DWORD)0);
}
  
and when i compile it says cant convert argument three from unsigned long to unsigned long [__stdcall*][void*] help please???

Share this post


Link to post
Share on other sites
Advertisement
CreateThread() expects a function pointer for the third parameter. The function should be of the form

DWORD WINAPI ThreadProc(LPVOID lpParameter);

To use this function as the third parameter you only need to write the name of the function (no parameters)

CreateThread(..., ThreadProc, ...);



Qui fut tout, et qui ne fut rien
Invader''s Realm

Share this post


Link to post
Share on other sites

  
#include<windows.h>
#include<windowsx.h>
#include<winbase.h>
#include<iostream.h>
DWORD WINAPI outs(LPVOID data)
{
cout<<"hello"<<endl;
return(0);
}
void main (void)
{
HANDLE threadHandles[300];
DWORD threadIDs[300];
int threadCount; //ini to zero

threadCount = 0;
threadHandles[threadCount] = CreateThread
(NULL,0,outs,(LPVOID)threadCount,0,&threadIDs[threadCount]);
}


i simplified the thing down to a basic example but then it gives me linker errors about some unresolved external symbols using new operators.

Share this post


Link to post
Share on other sites
ok i figured out why it wont link, the cout line causes errors, but i dont know how to use cout with multithreaded apps can any one help?

Share this post


Link to post
Share on other sites
ok i changed my compiler settings to use multithreading degubbing, and it compiles and links now. i changed the outs function to output hello so i can see if the threads execute and they dont. any ideas?

Share this post


Link to post
Share on other sites
ok i got the threads to work but only if i call the function outs first, is there a way to make the threads run w/o calling the function.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!