阐述
当多个client端进行请求时,server端的执行情况。
如果多个client在差不多的时间进行请求时,而server端的执行是按照顺序依次执行的,则表示的是线程安全;否则是线程不安全的。
涉及方法
主要涉及到的两个方法如下所示
// 针对的是服务端
ProcessState::self()->startThreadPool();
IPCThreadState::self()->joinThreadPool(true);
startThreadPool
重点关注下ProcessState::self()->startThreadPool()这个方法;
1.不使用该方法发现服务端的进程只有一个线程存在,还是主线程
xxx:/ # ps -A|grep "sample"
root 4657 4655 35928 3576 binder_ioctl 0 S sample_service
root 4664 4663 35928 3556 binder_ioctl 0 S sample_callback
root 4665 4660 35928 3592 binder_ioctl 0 S sample_callback
xxx:/ # ps -T -p 4657
USER PID TID PPID VSZ RSS WCHAN ADDR S CMD
root 4657 4657 4655 35928 3576 binder_io+ 0 S sample_se+
2.使用该方法发现该进程下有多个线程存在
xxx:/ # ps -A | grep sample
root 4597 4595 57460 4296 binder_ioctl 0 S sample_service
root 4601 4599 35928 3864 binder_ioctl 0 S sample_callback
root 4605 4603 35928 3880 binder_ioctl 0 S sample_callback
xxx:/ # ps -T -p 4597
USER PID TID PPID VSZ RSS WCHAN ADDR S CMD
root 4597 4597 4595 57460 4296 binder_io+ 0 S sample_service
root 4597 4598 4595 57460 4296 binder_io+ 0 S Binder:4597_1
说明
1.当只有一个单线程执行binder调用时,是线程安全的;
2.只要有多个binder线程执行,就不是线程安全的,大部分情况下都是存在多个binder线程进行操作的