Archived

This topic is now archived and is closed to further replies.

thread yield problem

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

Hi! Here's simple tight server loop with yield:
static void *mainServerLoop(void *s) {
    while(running) {
        // ...
        
        nlThreadYield();
    }
}

Then I have two cases:

CASE 1.

void main() {
    /* start the server thread */
    tid = nlThreadCreate(mainServerLoop, 0, NL_TRUE);
    nlThreadJoin(tid, (void **)&exitcode);
}


CASE 2.

void main() {
    /* run server without thread */
    mainServerLoop(0);
}
  
The problem is that case 1 eats up all processor time so that client application with 3d opengl graphics is damn slow. Also all other windows apps run very slow. However case 2 works much better. Why doesn't case 1 yield work to give time for other apps? Thanks. [edited by - stefu on July 24, 2002 4:28:33 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Tornado
Maybe you should try creating the new thread with a lower priority.


Ach, priorities? Didn''t think about them at all.

Thanks, I''ll try something.

Share this post


Link to post
Share on other sites
Well, I don''t have much experience with HawkNL (Just had a look at its docs), but any chance it could be nlThreadJoin() that''s causing the problem? The docs say that nlThreadJoin() doesn''t return until the thread you specify exists. Could be that it also steals cpu cycles while waiting?


- Goblineye Entertainment
The road to success is always under construction

Share this post


Link to post
Share on other sites
Hi!
Propably it is so.

I looked at source code, but don''t know much.

If it uses windows threads then nlThreadJoin is just WaitForSingleObject((HANDLE)threadID, INFINITE);

Or if POSIX system is used then pthread_join((pthread_t)threadID, status);

I think I''m using POSIX threads because I need PthreadVCE.dll.

But that''s no problem anymore. I go on without joining thread for now.

Thanks.

Share this post


Link to post
Share on other sites