LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 07-31-2006, 12:38 AM   #1
spaaarky21
Member
 
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?

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

Rep: Reputation: Disabled
There is a major difference between pthread_yield and *_np, the following is from man pages.
Quote:
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.
Quote:
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.

Quote:
...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.
http://predef.sourceforge.net/preos.html#sec17
 
  


Reply


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



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:00 AM.

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