Click here to Skip to main content
13,087,235 members (55,308 online)
Rate this:
Please Sign up or sign in to vote.
See more:

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 27-Feb-12 4:08am
Updated 27-Feb-12 19:19pm
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!
SAKryukov 27-Feb-12 17:37pm
Why on Earth?
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You need separate threads or processes to do this. Why the need for infinite loops? Why don't you want to use separate threads?
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
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
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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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[^])
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 28 Feb 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100