Click here to Skip to main content
15,878,809 members
Please Sign up or sign in to vote.
1.67/5 (3 votes)
See more:
Hi,

I have two infinite loops.
They both have to be running at the same time.

When i call one infinite loop. That's it. I'm stuck; I can not call the other infinite loop.

Is there another way to solve this problem then having 2 "threads", each running one loop?

Thank you for your help.
Posted
Updated 27-Feb-12 19:19pm
v3
Comments
DontLaughtIMLearning 27-Feb-12 10:10am    
The question on top should be: "How to use values generated by one infinite loop in another infinite loop?" I wonder how i can edit my question after having posted it!
Richard MacCutchan 27-Feb-12 10:29am    
Click on the "Improve question" link!
Sergey Alexandrovich Kryukov 27-Feb-12 17:37pm    
Why on Earth?
--SA

You need separate threads or processes to do this. Why the need for infinite loops? Why don't you want to use separate threads?
 
Share this answer
 
Comments
DontLaughtIMLearning 27-Feb-12 10:54am    
One of the loops is glutMainLoop() from "openGL". I have a sphere, growing. The other loop is the value of the radius of the sphere being calculated. The sphere needs to know it's radius value from the second loop, the one calculating the values. I'll just use two threads. Thank you. Was just wondering if there was another method :)
wizardzz 27-Feb-12 11:00am    
You could do it with event handlers, but that's still threading. Why is the radius value an infinite loop? Can't you just call a calculate radius function from the sphere growing loop?
enhzflep 27-Feb-12 11:06am    
Precisely!
Why someone would want to change the radius of a sphere during the course of it's drawing is beyond me. By definition, the shape would no longer be a sphere.

Surely, you'd just get the radius before each and every frame was drawn, as wizardzz said.
Maximilien 27-Feb-12 14:27pm    
@enhzflep
When you change the radius of a sphere, it will stay a sphere.
wizardzz 27-Feb-12 14:29pm    
Just a headsup, you can reply directly to enhzflep's comment by hitting the reply button on the right side of his post.
glutMainLoop is the main event loop of a glut OpenGL application; you just have to call it once.

You need to define a callback function (usually for the display) that will be called internally from the glutMainLoop function (with the glutDisplayFunc).

You will also need to define another callback function when the process is iddle, (use glutIdleFunc).

It is in that function that you should update the radius of the sphere, and that radius will (should?) be used in the display function to redraw the sphere with the appropriate radius.

(mostly inspired from http://www.lighthouse3d.com/tutorials/glut-tutorial/[^])
 
Share this answer
 
Comments
DontLaughtIMLearning 28-Feb-12 1:33am    
Thanks. I have leaning OpenGL for about 2 to 3 weeks. A few things still don't make sense. I'll read you tutorial and post my next question as an OpenGL question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900