# Multithreading: missing a yield instruction

**URL:** <https://discourse.glfw.org/t/multithreading-missing-a-yield-instruction/391>\
**Category:** support\
**Created:** [September 22, 2006, 3:43pm UTC](https://discourse.glfw.org/t/multithreading-missing-a-yield-instruction/391 "2006-09-22T15:43:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [September 22, 2006, 3:43pm UTC](https://discourse.glfw.org/t/multithreading-missing-a-yield-instruction/391/1 "2006-09-22T15:43:35Z")

</div>

**nobody** wrote on [Friday, September 22, 2006](https://sourceforge.net/p/glfw/discussion/247562/thread/7eede598/#7888):

Hi,

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

I propose:

glfwYield(void)

Windows: Sleep(0)  
Posix: pthread\_yield()

Comments are welcome.  
Ghostly yours,  
Red.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [September 23, 2006, 7:52am UTC](https://discourse.glfw.org/t/multithreading-missing-a-yield-instruction/391/2 "2006-09-23T07:52:48Z")

</div>

**[elmindreda](https://sourceforge.net/u/elmindreda/)** wrote on [Saturday, September 23, 2006](https://sourceforge.net/p/glfw/discussion/247562/thread/7eede598/#d7a6):

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [September 25, 2006, 7:50am UTC](https://discourse.glfw.org/t/multithreading-missing-a-yield-instruction/391/3 "2006-09-25T07:50:53Z")

</div>

**nobody** wrote on [Monday, September 25, 2006](https://sourceforge.net/p/glfw/discussion/247562/thread/7eede598/#506c):

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,  
Red

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [September 28, 2006, 9:18am UTC](https://discourse.glfw.org/t/multithreading-missing-a-yield-instruction/391/4 "2006-09-28T09:18:32Z")

</div>

**[elmindreda](https://sourceforge.net/u/elmindreda/)** wrote on [Thursday, September 28, 2006](https://sourceforge.net/p/glfw/discussion/247562/thread/7eede598/#506c/bc48):

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [October 11, 2006, 4:46pm UTC](https://discourse.glfw.org/t/multithreading-missing-a-yield-instruction/391/5 "2006-10-11T16:46:23Z")

</div>

**[elmindreda](https://sourceforge.net/u/elmindreda/)** wrote on [Wednesday, October 11, 2006](https://sourceforge.net/p/glfw/discussion/247562/thread/7eede598/#7888/858a):

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

[http://sourceforge.net/tracker/index.php?func=detail&aid=1575408&group\_id=72569&atid=534941](http://sourceforge.net/tracker/index.php?func=detail&aid=1575408&group_id=72569&atid=534941)
