Notifications
Clear all

[Closed] [SDK] Multithread example

Hi,
Is there any example of some plugin that uses multithreading?

I done multithreading in my object plugin using CreateThread from WinApi,
but the performance was poor, about 10-15 fps less than not using multithreading.

I am pasting part of the code below:

class myClass
{
	static DWORD WINAPI ThreadCreate(LPVOID);
	DWORD ThreadStart(LPVOID);

       void BuildMesh();
}

// struct for arguments
struct myArgs
{
	myClass* myclass;
	int a, b, c, d;
};

// ----

DWORD WINAPI MyClass::ThreadCreate(LPVOID lParam)
{
	myClass* _This = static_cast<myArgs*>(lParam)->myclass
	return _This->ThreadStart(lParam);
}

DWORD myClass::ThreadStart(LPVOID lParam)
{
        // some code to do in multithreading
	int start = static_cast<myArgs*>(lParam)->a;
	int end = static_cast<myArgs*>(lParam)->b;
}

void BuildMesh()
{
    DWORD ThreadID_1, ThreadID_2;
    HANDLE t[2];
    t[0] = CreateThread(NULL, 0, ThreadCreate, &a1, 0, &ThreadID_1);

    WaitForSingleObject(t[0], INFINITE);

    mesh.InvalidateGeomCache();
}
4 Replies

why do you think multithreading will be faster in this situation ? are you rendering while creating objects ? what else is user going to be doing while dragging out your object on screen ? most of the drawing will be handled on the gpu and any ui stuff is going to be minimal (and may well already be farmed off to another thread by max already).

I am trying only to speed up my mesh building. If let say, my mesh is combined from 1000 small meshes, I wanted to split computing by calling two thread functions that every one will process 500 meshes in the same time…
I pasted the code just to show how I am handling calling the thread function…

are they the same mesh by any chance ?

Yes, the same mesh, but transformed by matrix transform, some of them just moved to position and some also rotated and scaled… but are the same mesh objects…

in loop: when I transform my single mesh object I am combining it to the final mesh … and so