Jump to content
  • Advertisement
Sign in to follow this  
directNoob

Where does the function in my thread get executed?

This topic is 4347 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello again. I use a thread to create a terrain with the "fault formation" - algorithm. Everything worked well, but when I set the size of the file beeing created too high, the program limps. I assume that the called function isn´t executed in that thread. And now my question. When I have an Object with that fault formation function in the main program, I mean, I have defined an Instance that object in the main program, and I call that function from the thread discribed above, where does it get executed? I call this function with a pointer to the object in the main program. Is it executed in the main program or really in the thread? Thanks Alex

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by directNoob
And now my question.
When I have an Object with that fault formation function in the main program, I mean, I have defined an Instance that object in the main program, and I call that function from the thread discribed above, where does it get executed?


Well, if you call the function from within the thread you created then the function is executed in the context of that thread. Please don't take this the wrong way, but I really think you should read more about threads, what they are and how they work before you delve deeper into your problem.

Share this post


Link to post
Share on other sites
If by in the main program you mean in the main program's thread then no. It will get executed in teh main program's address space and process, but will be on its own seperate thread from the main program.

Cheers
Chris

Share this post


Link to post
Share on other sites
Your description is a little confusing... hope i got this right:

if you have 2 threads A(main), B(fault formation).
and you make an object(O) in A
then call O->fault_form from inside B
then: the function is running in thread B.

So, the program is stalling at some point...

When you call "fault_formation" do you lock something in the object (ie terrain data)?
Likely you should be, since it makes sense not to be able to call display() if the terain data is still being generated.
Your main thread could therefore be stalling because you actually are still waiting on the function to finish.
B calls O->fault_form(), thus locking something, so A calls O->display() and freezes up until thread B finishes.
You might need an extra buffer in there, so you can display one set of data while generating a new set.

Share this post


Link to post
Share on other sites
@Red Ant:
Jep, maybe you´re right. I have the book "Programming Windows" by Charles Pezold and he discribes thread good, I think. But he doesn´t use pointers to the main thread calling from the extra thread, except the PVOID param of course. So, for now, this is all I can do and all I can know, and I think this is enough to use it.

And by the way, thanks to all.

@KulSeran:
Quote:

if you have 2 threads A(main), B(fault formation).
and you make an object(O) in A
then call O->fault_form from inside B


This is absolutly right.

Quote:
When you call "fault_formation" do you lock something in the object (ie terrain data)?

I generate the height map in thread B with the algorithm. And when it´s finished, I put the the normalized(range 0.0f-1.0f)float field per element into the UCHAR field, which is in the range of 0 - 255. And when this is finished, I set a flag which says that the terrain is generated. And then the thread gets closed. The flag indicates the Render() Function of the Terrain class so that it can render the terrain. This means that it fills up the Vertex- and Indexbuffer in the main loop, where it gets rendered. When the buffers are filled, the flag is set to false so that the buffers don´t get filled up a second time.
This flag is important, because the Main prog enters the main loop before the terrain is gererated. Without the flag, the program would fill up the vertex buffer with the empty UCHAR terrain field, because the thread isn´t ready on that point. The UCHAR field is initialized with the value 0, so that no error can occure.
But ereything works, except that little "freezing" moment.

Greetings
Alex

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!