Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 07-31-2006, 12:38 AM   #1
Registered: Jun 2004
Location: Omaha, NE
Distribution: Ubuntu 7, Fedora Core 4
Posts: 192

Rep: Reputation: 30
pthread_yield() vs. pthread_yield_np()?

Hi everyone. After spending some time getting familiar with Java at my job, I decided to write a C++ class similar to Thread in Java where all the user has to do is override run() and call start(). The class uses pthreads behind the scenes.

I have used pthreads on Linux before while doing some computer graphics work and was used to using pthread_yield(). However, I originally started working on my thread class on my Mac which, as I'm sure everyone probably knows, is partially BSD-based. In the version of pthread included with OS X.4, there is no pthread_yield() but there is a pthread_yield_np(). I used it and it works on OS X but obviously won't compile on my Linux machine, which has a version of pthread with pthread_yield() but not pthread_yield_np().

So, my question is what are the differences between pthread_yield() and pthread_yield_np()? And more importantly, does anyone know of a way to get the code to compile on either system? I looked through pthread.h for something that might allow a simple #ifdef solution but didn't find anything. Any ideas?

Old 07-31-2006, 06:39 PM   #2
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
There is a major difference between pthread_yield and *_np, the following is from man pages.
pthread_yield_np - Notifies the scheduler that the current thread is willing to release its processor to other threads of the same or higher priority.
The pthread_yield subroutine forces the calling thread to relinquish use of its processor, and to wait in the run queue before it is scheduled again. If the run queue is empty when the pthread_yield subroutine is called, the calling thread is immediately rescheduled.

...does anyone know of a way to get the code to compile on either system?
preprocessor defines are the way to go, have a look at.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:11 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration