我编写了一个示例代码来验证僵尸线程,发现只有已关闭的代码显示在主线程上,而不显示在其他线程上。
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
&& ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this, new String[] {Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
} else {
Intent intent = new Intent(MainActivity.this, Main2Activity.class);
intent.putExtra("name", arrayList.get(position));
startActivity(intent);
}
}
});
'ps -AL'的输出
#include <pthread.h>
#include <stdio.h>
void *print(void *arg)
{
int *i = (int *) arg;
printf("Hi. I'm thread %d\n", *i);
sleep(20);
pthread_exit(NULL);
}
int main()
{
int i;
pthread_t tids[4], value[4];
void *retval;
for (i = 0; i < 4; i++) {
value[i] = i;
pthread_create(tids+i, NULL, print, (value+i));
}
pthread_exit(NULL);
for (i = 0; i < 4; i++) {
printf("Trying to join with tid %d\n", i);
//pthread_join(tids[i], &retval);
printf("Joined with tid %d\n", i);
}
return 0;
}
当我尝试更改逻辑以在主线程之前先终止另一个线程时,它在'ps -AL'输出中未显示为已取消