nptl

Java线程与Linux内核线程的映射关系

こ雲淡風輕ζ 提交于 2020-04-12 09:26:08
Linux从内核2.6开始使用NPTL (Native POSIX Thread Library)支持,但这时线程本质上还是轻量级进程(LWP)。 Java里的线程是由JVM来管理的,它如何对应到操作系统的线程是由JVM的实现来确定的。Linux 2.6上的HotSpot使用了NPTL机制, JVM线程跟内核轻量级进程有一一对应的关系 。线程的调度完全交给了操作系统内核,当然jvm还保留一些策略足以影响到其内部的线程调度,举个例子,在linux下,只要一个Thread.run就会调用一个fork产生一个线程。 Java线程在Windows及Linux平台上的实现方式,现在看来,是内核线程的实现方式。 这种方式实现的线程,是直接由操作系统内核支持的——由内核完成线程切换,内核通过操纵调度器(Thread Scheduler)实现线程调度,并将线程任务反映到各个处理器上。 内核线程是内核的一个分身。程序一般不直接使用该内核线程,而是使用其高级接口,即轻量级进程(LWP),也即线程。这看起来可能很拗口。看图: (说明:KLT即内核线程Kernel Thread,是“内核分身”。每一个KLT对应到进程P中的某一个轻量级进程LWP(也即线程),期间要经过用户态、内核态的切换,并在Thread Scheduler 下反应到处理器CPU上。) 这种线程实现的方式也有它的缺陷

What is the difference between NPTL and POSIX threads?

耗尽温柔 提交于 2019-12-20 10:21:15
问题 What is the basic difference between NPTL and POSIX threads? How have these two evolved? 回答1: POSIX threads (pthread) is not an implementation, it is a API specification (a standard, on paper, in english) of several functions whose name starts with pthread_ and which are defined in <pthread.h> header. POSIX is also a set of specifications. NPTL is now inside GNU Libc on Linux and is (or at least tries very hard to be) an implementation of POSIX threads. It is a bunch of source and binary code

How can I decide how much stack I can use after a call to pthread_attr_setstacksize?

故事扮演 提交于 2019-12-10 11:42:06
问题 I am trying to debug some code regarding stack usage. I have made the following test program (just as an example to figure out how the pthread library works): #include <string.h> #include <pthread.h> #include <stdlib.h> #include <assert.h> #include <limits.h> #include <stdio.h> static void *threadFunc1(void *arg) { char arr[5000]; printf("Hello fromt threadFunc1 address of arr:%p\n", &arr); return; } static void *threadFunc2(void *arg) { char arr[10000]; printf("Hello fromt threadFunc2 adress

NPTL caps maximum threads at 65528?

空扰寡人 提交于 2019-12-08 23:16:22
问题 The following code is supposed to make 100,000 threads: /* compile with: gcc -lpthread -o thread-limit thread-limit.c */ /* originally from: http://www.volano.com/linuxnotes.html */ #include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <pthread.h> #include <string.h> #define MAX_THREADS 100000 int i; void run(void) { sleep(60 * 60); } int main(int argc, char *argv[]) { int rc = 0; pthread_t thread[MAX_THREADS]; printf("Creating threads ...\n"); for (i = 0; i < MAX_THREADS && rc

Kernel Level Thread Library

岁酱吖の 提交于 2019-12-08 13:26:28
问题 I have to implement kernel level thread but while searching on the net I found that there are three ways to create kernel level thread in linux: NPTL kthread linuxThreads It was written somewhere that linuxThreads are now abandoned. But I am unable to find current support of NPTL & kthread. Also I am unable to find any source that can simply explain me how to use their functionality. Which is the currently supported and good library to use kernel level thread? Also pls share any resource for

Setting the thread /proc/PID/cmdline?

北城余情 提交于 2019-12-01 09:20:39
On Linux/NPTL , threads are created as some kind of process. I can see some of my process have a weird cmdline: cat /proc/5590/cmdline hald-addon-storage: polling /dev/scd0 (every 2 sec) Do you have an idea how I could do that for each thread of my process? That would be very helpful for debugging. /me now investigating in HAL source thanks miguel.de.icaza If you want to do this in a portable way, something that will work across multiple Unix variations, there are very few options available. What you have to do is that your caller process must call exec with the argv [0] argument pointing to

Setting the thread /proc/PID/cmdline?

心已入冬 提交于 2019-12-01 06:39:16
问题 On Linux/NPTL , threads are created as some kind of process. I can see some of my process have a weird cmdline: cat /proc/5590/cmdline hald-addon-storage: polling /dev/scd0 (every 2 sec) Do you have an idea how I could do that for each thread of my process? That would be very helpful for debugging. /me now investigating in HAL source thanks 回答1: If you want to do this in a portable way, something that will work across multiple Unix variations, there are very few options available. What you

Java I/O vs. Java new I/O (NIO) with Linux NPTL

孤街醉人 提交于 2019-11-29 19:45:58
My webservers use the usual Java I/O with thread per connection mechanism. Nowadays, they are getting on their knees with increased user (long polling connection). However, the connections are mostly idle. While this can be solved by adding more webservers, I have been trying to do some research on the NIO implementation. I got a mixed impression about it. I have read about benchmarks where regular I/O with the new NPTL library in Linux outperforms NIO. What is the real life experience of configuring and using the latest NPTL for Linux with Java I/O? Is there any increased performance? And on

Java I/O vs. Java new I/O (NIO) with Linux NPTL

夙愿已清 提交于 2019-11-28 15:34:03
问题 My webservers use the usual Java I/O with thread per connection mechanism. Nowadays, they are getting on their knees with increased user (long polling connection). However, the connections are mostly idle. While this can be solved by adding more webservers, I have been trying to do some research on the NIO implementation. I got a mixed impression about it. I have read about benchmarks where regular I/O with the new NPTL library in Linux outperforms NIO. What is the real life experience of