Java Native Pthreads for Win32 Platform Bala Dhandayuthapani Veerasamy Research Scholar in Information Technology, Manonmaniam Sundaranar University, Tirunelveli, Tamilnadu, India Dr. G. M. Nasira, Ph.D Assistant Professor/Computer Science, Chikkanna Govt Arts College, Tirupur, Tamilnadu, India Abstract- Many modern operating systems directly support both time-sliced and multiprocessor threading with a process scheduler. The kernel of an operating system allows programmers to manipulate threads via the system call interface. Java includes threading facility within the language itself rather than handling threads as a facility of the underlying operating system. This research finding focuses on how Java can facilitate Pthreads through JNI, which can exploit in Java threads and Native Pthreads to execute in hybrid model. I. INTRODUCTION There are two types of threading library [1] available, implicit and explicit. Implicit threading libraries take care of much of the minutiae needed to create, manage, and synchronize threads. The flexibility of implicit threading libraries are not as great as we might find with explicit threading. However, a majority of algorithms that can be written concurrently can take advantage of the limited scope of features within the implicit libraries. There are two libraries in implicit threading, OpenMP and Intel TBB. Explicit threading libraries require the programmer to control all aspects of threads, including creating threads, associating threads to functions, and synchronizing and controlling the interactions between threads and shared resources. The two most prominent threading libraries in use today are POSIX threads (Pthreads) and Windows Threads by Microsoft. Java threads are scheduled requires an understanding of the particular virtual machine involved. There are two basic variations here: The green threads [2] are scheduled by the virtual machine itself. This is the original model for Java Virtual Machine mostly follows the idealized priority based scheduling. This kind of thread never uses operating system threads library. The native threads [2] are scheduled by the operating system that is hosting the virtual machine. The operating system threads are logically divided into two pieces: user level threads and system level threads. The operating system itself that is the kernel of the operating system lies at system level threads. The kernel is accountable for managing system calls on behalf of programs that run at user level threads. Pthreads [3] is a standardized model for dividing a program into subtasks whose execution can be interleaved or run in parallel. The "P" in Pthreads comes from POSIX (Portable Operating System Interface), the family of IEEE operating system interface standards in which Pthreads is defined (POSIX Section 1003.1c to be exact). Implementations of the API are available on many Unix-like POSIX-conformant operating systems such as FreeBSD, NetBSD, OpenBSD, GNU/Linux, Mac OS X and Solaris. DR- DOS and Microsoft Windows implementations also exist, which provides a native implementation of POSIX APIs [4] [5] such as Pthreads-win32, which implements Pthreads on top of existing Windows API. Windows does not support the Pthreads standard natively; therefore the Pthreads-win32 project [4] [5] seeks to provide a portable and open-source wrapper implementation. It can also be used to port Unix software with little or no modification to the Windows platform. The mingw-w64 “Minimalist GNU for Windows” project also contains a wrapper implementation of Pthreads, winpthreads, which tries to use more native system calls than the Pthreads-win32 project. The Pthreads-win32 [5] is normally implemented as a dynamic link library (DLL). This has some notable advantages from the Win32 point of view, but it also more closely models existing Pthreads libraries on UNIX which are usually shared objects (e.g. libpthread.so). Some of the Pthreads methods [6][7] are listed in bellow Table I. TABLE I PTHREAD METHODS Method Usage int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void*(*start_routine) (void),(void *arg) Creates a new thread, initializes its attributes, and makes it runnable. The pthread_create subroutine creates a new thread and initializes its attributes using the thread attributes object specified by the attr parameter. void pthread_exit(void *value_ptr) It terminates the calling thread. The pthread_exit subroutine terminates the calling thread safely, and stores a termination status for any thread that may join the calling thread. pthread_t pthread_self() It returns the calling thread's identifier. The pthread_self subroutine returns the calling thread's identifier pthread_num_processors_np() It get the number of processors (CPUs) in use by the process int sleep (unsigned int seconds ) It suspends the execution of the current thread until the timeout interval elapses. exit(EXIT_SUCCESS) It signifies the application was successful. int pthread_setaffinity_np(pthread_t thread, size_t cpusetsize, const cpu_set_t *cpuset) It sets the CPU affinity mask of the thread thread to the CPU set pointed to by cpuset. int pthread_getaffinity_np(pthread_t thread, size_t cpusetsize, cpu_set_t *cpuset) It returns the CPU affinity mask of the thread thread in the buffer pointed to by cpuset.