Multithreaded Programming Guide

Exit Print View

Updated: July 2014
 
 

Including <thread.h> or <pthread.h>

The include file <thread.h> contains declarations for the Oracle Solaris threads functions. To call any Oracle Solaris thread functions, your program needs to include <thread.h>. This file enables you to produce compiled code that is compatible with earlier releases of the Oracle Solaris software.

The include file <pthread.h> contains declarations for the Pthreads functions and is required if your program uses Pthreads.

You can mix Oracle Solaris threads and POSIX threads in the same application by including both <thread.h> and <pthread.h> in the application. Then when linking and compiling you need to specify the –lpthread flag to link in the pthread APIs.

When using –mt, the Oracle Solaris threads APIs will be linked automatically. Always use the –mt option instead of listing –lthread explicitly. To use Pthreads, specify the –mt option and –lpthread option on the link command line. The libpthread library provides an interface to libthread, so you still need libthread when using Pthreads.