Sign in to follow this  
Aidamina

MultiThreading and OpenGL

Recommended Posts

Aidamina    100
I am making a downloader with opengl graphics in c++, but in order to do this i need to create a second thread next to the main winmain thread. When i use the CreateThread(... function the applications seems to lock up/no more frames are drawn. Anybody got some experience with this and does any1 know where to initialise a thread. Greetz, Me

Share this post


Link to post
Share on other sites
doynax    850
Why would you need multithreading in the first place? Wouldn't it be enough to poll for incoming data in the socket and continue rendering as usual in the meantime?

Make sure that you only call OpenGL from one of the threads and that all of the mutexes are getting unlocked properly.
Do some debugging to check how far into the code each thread reaches.

Multitheading is hard and my first guess is that you've got synchronization issues (a deadlock). Besides that I can't give you much advice without further details of the code and your communication mechanism.

edit: Maybe I didn't read your post. Does the application hang up simply because you create a test thread regardless of what the thread does?

Here's a simple example which should work:
DWORD WINAPI dummyThreadFunc(void *param) { 
return 0;
}

HANDLE spawnAThread(void) {
return CreateThread(NULL, 0, dummyThreadFunc, NULL, 0, NULL);
}
Check if the application stops rendering after calling the spawn function.

[Edited by - doynax on March 27, 2005 1:18:13 PM]

Share this post


Link to post
Share on other sites
_the_phantom_    11250
Quote:
Original post by doynax
Make sure that you only call OpenGL from one of the threads


and importantly, make sure the thread you draw from is the one the context is currently associated with (so if you created the context in the main thread drawing from another thread wont work until you free it from the main thread and reaquire it in the worker thread)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this