View Full Version : Can I make multithread program with glut on Linux
I am using Linux, OpenGL, GLUT to make my program. Can I make the program multithreading? How to do it then?
Thanks a lot!
Sure you can.You can either use system calls directly(the clone() call that is) or a library like pthreads(which I would recommend).I have to warn you though.Unless you really,really need threads for something(like paging) it would be quite unwise to use them.Especially if you don't have much experience.There are a lot of probles(like irrational behaviour,debugging problems etc.) which can make your life pretty hard and the payoffs aren't always that great.So be carefull!
PS:As you might have guessed I've recently tried using them until one day some nice people in white came along with a shirt that's worn backwards,so I dropped them until I have some working code first.
Thank you for advice.
I am using joystick with my program, if I donot use thread, my program has to act like this:
which makes the sampling two slow.
Is there a frame work or sample showing how to make a glut multithreading program?
03-12-2002, 09:13 AM
I think threads are not what you need. You need a timer. Measure the time since your last frame, multiply that with your joystick position. Use the result for your movement updates. This way you'll be independent of frame rate.
How is this an 'advanced OpenGL topic' ? ???
Wrong forum, we need all the space we can get for the serious topics, pal.
03-12-2002, 09:17 AM
What do you mean by "which makes the sampling two slow"?
Do you mean it slows down your application? If you get any significant slowdown just reading a joystick, you probably have much bigger problems than not being multithreaded and need to optimize a bit.
Or do you mean that you dont get input often enough? If thats what you mean, I have to ask you one question: Why do you need to get input more often than once per frame? Doing so would mean you provide no visual input on from your first sampling, so the user would never know the difference. If you are worried about missing some samples, I would say not to worry about it. If the user pressed a button and then released it so fast that you never had a chance to see the event, then the user made a very conscious effort to do a quick tap, and the user would probably think that in their haste they didnt hit the button right or press it all the way down. I'm not saying you dont need this level of accuracy, but more than likely you dont.
That said, sorry but I have no linux experience http://www.opengl.org/discussion_boards/ubb/frown.gif
u'v got what I mean, I really need to sample more then once per frame, since theoritically, I am going to simulate delay in my program, so I may need the data I sampled half a frame before to update my scene. Does it make sense?
I am using timer in my programmer now, but although I sent the timer to be 5ms, the function will be called only in 15ms interval, the draw() function will take 10ms.
So I cannot sample more than once per frame.
I got what u mean now, it is a good suggestion, I may do it that way, but I am still interest in how to make it multithreaded.
Do a search for the pthreads library on google to find the homepage.Also get(though you propably allready have them) the manpages for the lib and you should have everything you need(although you might have to take a few look at the headers,pthread.h for some undocumented features like mutexes etc.).I should warn you again though that unless you really need them,or unless you're optimizing your code threads will just waste your time and patience which could be used for far more usefull things.
Rob The Bloke
03-12-2002, 02:49 PM
As a general rule :
Don't use multi-threading (Unless there is no way around it, and it HAS to be used).
Save yourself a lot of grief, hard to track errors and don't use any extra threads! I doubt very much that your code needs them or will benefit in any way from using them.
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.