Sun Java Solaris Communities My SDN Account Join SDN
 
Article

Alternate Thread Library (T2) in Solaris 8 OS

 
By J. K. Shah, June 2002  

Questions

  1. Where can I find background information on: Solaris vs. POSIX threads, bound vs. unbound threads, MxN vs. 1:1?
  2. What is the alternate thread library (T2) of the Solaris 8 Operating Environment (OE)?
  3. What is the main difference between the default thread library and the T2 library?
  4. What kind of behavior difference can be expected from switching over to the T2 library?
  5. What are the advantages of using T2 over the default thread library in the Solaris 8 OE?
  6. Which maintenance level of Solaris 8 is recommended for use of the alternate thread library?
  7. Why not make the T2 library the default for all Solaris 8 customers via a patch?
  8. Which thread library is available in the Solaris 9 OE?
  9. Can I use the alternate thread library with my existing binaries for my application?
  10. How can I use the T2 library as my default thread library for all applications on my server?
  11. How can you make any one application use the alternate thread library?
  12. What if my application binaries have setuid flags set?
  13. Can different processes of the same application use different thread libraries at the same time?
  14. How do I relink so that the alternate thread library is always used, if available, and I still have a single set of binaries for all Solaris versions?
  15. If I use the T2 library, do I have to retest my application?
  16. Is the T2 library supported on the Solaris 8 OE?
  17. Where do I get more information on the T2 library for the Solaris 8 OE?

Answers

1. Where can I find background information on: Solaris vs. POSIX threads, bound vs. unbound threads, MxN vs. 1:1?

2. What is the alternate thread library (T2) of the Solaris 8 Operating Environment (OE)?

Solaris 8 has a new implementation of the thread library. However, in Solaris 8 it is provided as an alternate thread (T2) library. The path of the T2 library is /usr/lib/lwp/libthread.so.1 (the default thread library [T1] is available at /usr/lib/libthread.so.1).

3. What is the main difference between the default thread library and the T2 library?

The main difference between the two thread libraries is the architecture of implementation. The default threads library implementation is a two-level model in which user-level threads are multiplexed over possibly fewer lightweight processes, or LWPs. An LWP is the fundamental unit of execution that is dispatched to a processor by the operating system. This model is also known as MxN implementation.

The Solaris 8 Operating Environment provides an alternate threads library implementation, a one-level model, in which user-level threads are associated one-to-one with LWPs. This model is also known as 1:1 implementation.

4. What kind of behavior difference can be expected from switching over to the T2 library?

When using the alternate one-level threads library, it could create more LWPs than the default threads library using unbound threads. Each LWP requires system memory for a stack and other data structures to use while executing in the kernel -- approximately 10 Kbytes for a 32-bit operating system and 20 Kbytes for a 64-bit operating system. Running applications with many thousands of threads might require additional physical memory in the system. The T2 library avoids the overhead of multiplexing and scheduling the threads over LWP, and hence, it shows better performance compared to the default thread library of Solaris 8. However, there could be a few cases where the default thread gives better performance than the T2 library.

For further information, refer to the Ping-Pong example in the white paper listed in Question 17, Multithreading in the Solaris Operating Environment.

5. What are the advantages of using T2 over the default thread library in the Solaris 8 OE?

The advantages of T2 over the default thread library are expected to be as follows:

  • More robust implementation suited for modern multithreaded applications
  • More scalability, compared to the default thread library
  • Better performance
  • Less overhead
  • Solaris 9 readiness path

The latest SPECjbb2000 results posted by Sun for the Sun Fire 15000 with 104 processors were run using LD_LIBRARY_PATH=/usr/lib/lwp on Solaris 8 Update 7 (see SPECjbb2000).

6. Which maintenance level of Solaris 8 is recommended for use of the alternate thread library?

Solaris 8 Update 7 (2/2002) release is recommended for use of the T2 library since it contains all the performance enhancements and patches. If your release level is lower than Update 7, then you can apply the maintenance update 7 patch cluster or the following patches related to T2:

  • 108528-13: SunOS 5.8: kernel update patch
  • 108827-17: SunOS 5.8: /usr/lib/libthread.so.1 patch

(These patches can be applied from SunSolve to the installed Solaris 8 release so that the kernel level and T2 library level are updated to Solaris 8 Update 7 level.)

The version of the T2 library in Solaris 8 Update 7 has been improved over older versions in previous Solaris 8 updates, with the addition of user-level sleep queues and adaptive mutex locking. It is the same as the default thread library included in the full release of Solaris 9, which is backported to Solaris 8.

7. Why not make the T2 library the default for all Solaris 8 customers via a patch?

The T2 library is based on a completely different architecture. This new architecture means that it is not a fix for the existing default thread library (even though many applications run better with the T2 library). It can be considered as a backport of a future technology from Solaris 9, made available to Solaris 8 Update 7 customers as an optional implementation. Due to the change in architecture, it cannot be made the default thread library in Solaris 8 via a patch.

(Note: Sun has the T2 library as the default thread library in Solaris 9. See question 8.)

8. Which thread library is available in the Solaris 9 OE?

The T2 library of Solaris 8 Update 7 is the only library available in Solaris 9. As such, it is the default thread library in Solaris 9. The default thread library of Solaris 8 has been retired with the release of Solaris 9.

9. Can I use the alternate thread library with my existing binaries for my application?

Since the T2 library uses the same API/ABI interface as the default thread library of Solaris 8, it can be used with existing application binaries also.

10. How can I use the T2 library as my default thread library for all applications on my server?

To make the T2 library the default in the Solaris 8 OE, execute the following commands. The crle commands modify the runtime environment of the system permanently to search first in the /usr/lib/lwp for the libthread library for 32 bit and 64 bit, respectively:

crle -a /usr/lib/libthread.so.1 -o /usr/lib/lwp
crle -64 -a /usr/lib/64/libthread.so.1 -o /usr/lib/lwp/64

For more information, please refer to the manual page of crle.

The ldd command, which lists the dynamic dependencies of executable files or shared objects, can be used to verify the path of the library being loaded by the executables or shared objects in the current environment. For more information on the ldd command, please refer to the manual page of ldd.

11. How can you make any one application use the alternate thread library?

Generally, changing the LD_LIBRARY_PATH to include /usr/lib/lwp before /usr/lib is enough at runtime to use the T2 library. However, the environment variable does not work for binaries with setuid or setgid flags enabled unless it is a secured directory. By default, only /usr/lib/secure is a secured directory. If your application uses setuid as root functions/flags, then you will have to make /usr/lib/lwp a secured directory permanently using crle.

To include the /usr/lib/lwp as a secured directory, execute the following commands as root with all the secured directories in the system:

crle -s /usr/lib/secure:/usr/lib/lwp

If the application is a 64-bit application, then the environment variable LD_LIBRARY_PATH_64 will have to be modified to include /usr/lib/lwp/64. Examples of settings for the environment variables are as follows:

        LD_LIBRARY_PATH=/usr/lib/lwp
        LD_LIBRARY_PATH_64=/usr/lib/lwp/64

The ldd command can be used to verify the path of the library being loaded by the executables or shared objects in the current environment.

12. What if my application binaries have setuid flags set?

If the application contains binaries with setuid/setgid flags on, then one of the following is necessary to make those binaries use the T2 library:

  • Relink the binaries with -R /usr/lib/lwp (see Question 14).
  • OR Use crle to make the T2 library the default library for the system (see Question 10).
  • OR Use crle to make /usr/lib/lwp a secured directory, and use LD_LIBRARY_PATH=/usr/lib/lwp (see Question 11).

13. Can different processes of the same application use different thread libraries at the same time?

Yes. The T2 library was designed to work along with the default thread library in a USYNC_PROCESS (LWP-based) synchronized application. However, at one time, a single process uses only one implementation of the thread library. If two processes share memory/mutexes, it will still work if one process loads the default thread library and the other loads the T2 library.

14. How do I relink so that the alternate thread library is always used, if available, and I still have a single set of binaries for all Solaris versions?

Relink the end binaries with ' -R /usr/lib/lwp.' For example:

  POSIX
   cc -mt ... -lpthread ... -R /usr/lib/lwp (32-bit)
   cc -mt ... -lpthread ... -R /usr/lib/lwp/64 (64-bit)

  Solaris
   cc -mt ... -R /usr/lib/lwp (32-bit)
   cc -mt ... -R /usr/lib/lwp/64 (64-bit)

man -M /opt/SUNWspro/man cc describes -R as

-Rdir[:dir]

A colon-separated list of directories is used to specify library search directories to the runtime linker. If present and not null, it is recorded in the output object file and passed to the runtime linker. If binaries are generated with -R /usr/lib/lwp, this tells the linker to use /usr/lib/lwp as a search directory for libraries before the default paths.

This change has the following effects on different Solaris releases:

  • Solaris 7 -- Since /usr/lib/lwp does not exist in Solaris 7, it will skip the path and use the default Solaris 7 thread library.
  • Solaris 8 -- It will first search for libraries in /usr/lib/lwp. This means that the T2 library is selected first, and hence the application will use the T2 library on Solaris 8.
  • Solaris 9 -- In Solaris 9, the contents of the /usr/lib/lwp path are soft links back to the contents of /usr/lib and hence will use the default thread library of Solaris 9 (which is actually the T2 library of Solaris 8 Update 7).

Only the final binaries have to be relinked with the -R option to use the T2 library for the application.

15. If I use the T2 library, do I have to retest my application?

Sun recommends that the application be retested with the T2 library before using it for mission-critical production environments.

16. Is the T2 library supported on the Solaris 8 OE?

Yes, the T2 library is fully supported on Solaris 8. However, it is strongly recommended that you first upgrade to Solaris 8 Update 7 to use the T2 library.

17. Where do I find more information on the T2 library for the Solaris 8 OE?

For more information, please check out the following:

About the Author

J.K. Shah is a software engineer in the Market Development Engineering organization at Sun. He works with Sun's ISVs, helping them to adopt emerging Sun technologies. He holds a B.E. in Electronics Engineering and an M.S. in Computer Science.

Rate and Review
Tell us what you think of the content of this page.
Excellent   Good   Fair   Poor  
Comments:
Your email address (no reply is possible without an address):
Sun Privacy Policy

Note: We are not able to respond to all submitted comments.