Multithreading: missing a yield instruction

nobody wrote on Friday, September 22, 2006:


I am missing the yield instruction within GLFW. When using threads, I must use the platform specific instruction.

I propose:


Windows: Sleep(0)
Posix: pthread_yield()

Comments are welcome.
Ghostly yours,

elmindreda wrote on Saturday, September 23, 2006:

Hmm, yes, that can be added, but it seems easier to use the MS semantic and do it with glfwSleep(0).

nobody wrote on Monday, September 25, 2006:

After a quick review, yield and sleep are different functions under UNIX systems:
yield(void) and Sleep(int).

Please note windows function Sleep cumulates both semantics:
Win_Sleep(0) = Unix_Yield()
Win_Sleep(105) = Unix_Sleep(105)

A call to Unix_Sleep(0) makes the thread wait 0 ms.

I see Java uses the same semantics than in MS Windows. We could use then your proposed function name glfwSleep provided it does have the same behaviour than the MS one on all platforms.

Ghostly yours,

elmindreda wrote on Thursday, September 28, 2006:

Sorry, my previous message was a bit unclear.

What I meants was that rather than introduce a new entry point (glfwYield), the existing glfwSleep could be made to call pthread_yield or its Windows analogue if passed a time value of zero, since it makes little sense request to sleep for zero milliseconds anyway. It keeps the API from growing, while giving you the functionality you require.

elmindreda wrote on Wednesday, October 11, 2006:

I made a feature request item of this thread. Thank you for pointing this out.