Jump to content
  • Advertisement
Sign in to follow this  
RichardBurns_206

snt there a way to make threads of winapi safe ?

This topic is 2525 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

the problem is when i create a thread i cant make sure its dead before i reexecute its clone. :P
is there a way to make sure a winapi Createthread is dead safely ?
im asking because when i use this on winapi allmst allways there is unpredictable crashes. that happens much common when using winapi spesific functions.
and on msdn most programmers commented that createthread is a depricated function and we hawe to use threadind the old way :D ?
is that true ? isnt there a way to make threads of winapi safe ?

Share this post


Link to post
Share on other sites
Advertisement
When a thread exits, the handle becomes signalled. So you can use WaitForSingleObject() on the thread HANDLE to wait for the thread to become signalled, or to poll the handle.

Share this post


Link to post
Share on other sites
Why are you trying to "reexecute" a "clone" of the thread? Thread creation is expensive enough that it should be avoided where possible. You could perhaps change the logic so that the thread isn't 100% tied to the task, and that the thread can pull tasks from some thread-safe task queue.

Share this post


Link to post
Share on other sites

Why are you trying to "reexecute" a "clone" of the thread? Thread creation is expensive enough that it should be avoided where possible. You could perhaps change the logic so that the thread isn't 100% tied to the task, and that the thread can pull tasks from some thread-safe task queue.
the thread i thinked of doues gui part in background for performance cases ( loading icons of objects) that way it looks far better :P . and sometimes it executes repeadedly so i hawe to kill copies to not let owerloading .
threading looks like a good way to not wait for somethin you may or maynot need . ie icons :P

Share this post


Link to post
Share on other sites
You might want to look at a lock to prevent the multiple creation, rather than have the thread die and be recreated. Actually, with C++, you could look at a singleton possibly, since this would be one of those cases where a singleton would be useful (from what I can guess from your description).

EDIT: I don't write a lot of mutli-threaded code, but I believe you want to use a mutex.

Share this post


Link to post
Share on other sites

the thread i thinked of doues gui part in background for performance cases ( loading icons of objects) that way it looks far better. and sometimes it executes repeadedly so i hawe to kill copies to not let owerloading .
[/quote]
Then using a single background thread with a task queue might be better. Dynamically spawning threads will probably be detrimental to performance.

Also don't forget to ask regular people what they think of icons loading asynchronously. I think that lots more companies would be doing it if it "looked better" to the average user! It has been my experience that UIs that "jump" or change without interaction are distracting and more difficult to use.

Finally Windows already provides a mechanism for asychronous I/O, I/O completion ports. The boost library provides a wrapper, called asio.

In any case, think very carefully before you introduce asynchronous behaviour into your application. It is notoriously difficult to get right. Unless you are extremely disciplined, you will have an unstable and buggy application. Who cares how fast it loads, if it is unreliable?

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!