Skip to content

Commit

Permalink
019060421update
Browse files Browse the repository at this point in the history
  • Loading branch information
0xcaffebabe committed Jun 4, 2019
1 parent 8f97583 commit 3ef7416
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
26 changes: 26 additions & 0 deletions 操作系统/进程与线程.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,32 @@ P为CPU空转的概率
- 屏蔽中断:进程进入临界区后屏蔽所有中断,这样系统就无法切换到其他进程了
- 锁变量
- 严格轮换法:
连续测试一个变量直到某个值出现为止,称为**忙等待**
- Peterson解法
- TSL 指令
调用enter() -> 忙等待,直到获得锁 -> 调用leave()
**优先级反转问题**
**生产者-消费者问题**
### 信号量
是原子操作
### 互斥量
信号量的一个简化版本
*思考:自旋锁是不是就是忙等待*
- 快速用户区互斥量futex
-
















Expand Down
73 changes: 73 additions & 0 deletions 移动开发/安卓/IPC机制.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# IPC机制
IPC:进程间通信
## 安卓中的多进程模式
### 开启多进程
在清单文件中添加:android:process
```xml
<activity android:name=".Main2Activity" android:process=":p1"></activity>
```
代表该activity以包名.p1作为进程名进行运行
### 多线程造成的问题
- 静态成员、单例模式完全失效
- 线程同步机制失效
- SharedPrerences可靠性下降
- Application多次创建
## IPC
### Serializable接口
java当中自带的序列化接口
### Parceable接口
实现接口:
```java
public class User implements Parcelable {

private String name;

private int age;

protected User(Parcel in) {
name = in.readString();
age = in.readInt();
}

// 省略构造器

public static final Creator<User> CREATOR = new Creator<User>() {
@Override
public User createFromParcel(Parcel in) {
return new User(in);
}

@Override
public User[] newArray(int size) {
return new User[size];
}
};

@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(name);
dest.writeInt(age);
}


//省略toString
}
```
这样,就可以直接在Intent中传送User类型的对象了:
```java
Intent intent = new Intent();
intent.setClass(MainActivity.this,Main2Activity.class);
intent.putExtra("user",new User("小明",15));
startActivity(intent);
```
## 安卓中的IPC方式
- Bundle
- 文件共享
*SharedPreferences本质:XML*
- Messenger

0 comments on commit 3ef7416

Please sign in to comment.