Skip to main content
gamedev.net
🔒 Locked

thread yield problem

Started by stefu 4 replies 250+ views
Original Post
stefu
stefu
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]
stefu
stefu
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.

stefu
stefu
Damn it, there''s no way to change thread priority in HawkNL or SDL
Tornado
Tornado
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
Goblineye EntertainmentThe road to success is always under construction
stefu
stefu
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.