加锁 synchronize
来源:互联网 发布:炫酷导航页面源码 编辑:程序博客网 时间:2024/05/15 06:03
(gdb) p *((UIButton*)0x6d98ce0)
$1 = {
<UIControl> = {
<UIView> = {
<UIResponder> = {
<NSO
_backgroundView = 0x6dc0210,
_imageView = 0x0,
_titleView = 0x6dc00c0,
_initialized = 1 '\001',
(gdb) po 0x6dc00c0
<UIButtonLabel: 0x6dc00c0; frame = (15 6; 58 22); text = '记录(2)'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x6dc02d0>>
(gdb)
//make a call
NSString * teluri = [NSStringstringWithFormat:@"tel:%@", phoneNumber];
NSURL * url = [NSURL URLWithString:teluri];
[[UIApplicationsharedApplication] openURL:url];
@synchronized (A) {} 的本质就是根据一个标志A对一段代码进行加锁,开始处lock(sign), 结束时 unlock(sign)
而不是对A进行加锁
//thread 1
m_strTest =@"0";//this is needed, form_strTest should not be nil, if it is nil, it won't work
@synchronized(m_strTest)
{
NSLog(@"@synchronized(m_strTest)");
sleep(200);
}
//thread 2
sleep(1);
NSLog(@"========= begin");
@synchronized(m_strTest)
{
m_strTest = [NSStringstringWithFormat:@"%d", i];
NSLog(@"========= m_strTest is %@",m_strTest);
}
NSLog(@"========= end");
in this case,//thread 2 stopped at @synchronized(m_strTest)
sleep(1);
NSLog(@"========= begin");
//@synchronized(m_strTest)
{
m_strTest = [NSStringstringWithFormat:@"%d", i];
NSLog(@"========= m_strTest is %@",m_strTest);
}
NSLog(@"========= end");
in this case, the code will run
===
m_strTest =@"0";
@synchronized(m_strTest)
{
NSLog(@"@synchronized(m_strTest)");
m_strTest =@"100";
sleep(200);
}
--
sleep(1);
NSLog(@"========= begin");
@synchronized(m_strTest)
{
m_strTest = [NSStringstringWithFormat:@"%d", i];
NSLog(@"========= m_strTest is %@",m_strTest);
}
NSLog(@"========= end");
synchronized do not work at here,代码都会执行到,因为 m_strTest改变了,2个锁变量标识不一样
- 加锁 synchronize
- Java多线程实现窗口背景颜色轮换(synchronize加锁)
- synchronize
- 加锁
- 加锁
- 加锁
- 加锁
- 加锁
- 加锁
- 加锁
- synchronize函数
- java synchronize
- Synchronize函数
- synchronize java
- synchronize关键字
- synchronize用法
- synchronize用法
- synchronize原理
- var that=that
- Android类参考---Fragment(三)
- SearchView
- linux unzip 命令详解
- XML报表
- 加锁 synchronize
- 如何用SQL语句查询一个数据表所有字段的类型
- ArcGIS点击地图查询
- 解决RTX开发问题:检索 COM 类工厂中 CLSID 为 {79210E58-99EB-45D0-8890-763EFEAA143F} 的组件时失败,原因是出现以下错误: 80040154。
- sed命令基本用法(vbird)
- 十招教你从程序员转向企业家
- IOCP编程注意事项
- 服务器上的图片下载
- 项目管理型企业精益化管理与准时制(JIT)运作