Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.0.15.1 版本里的线程安全问题 #655

Closed
kobe1941 opened this issue Feb 13, 2019 · 9 comments
Closed

3.0.15.1 版本里的线程安全问题 #655

kobe1941 opened this issue Feb 13, 2019 · 9 comments

Comments

@kobe1941
Copy link

image

用的最新的版本 3.0.15.1,依然有线程安全问题。

对应有问题的代码,大概在这里
image

@kinarobin
Copy link
Collaborator

@kobe1941 崩溃日志能不能全一点哟?

@kobe1941
Copy link
Author

@kinarob 该有的都有了呀,崩溃类型SIGSEGV,具体所在的类和函数,只是bugly解析代码行数失败了

@kinarobin
Copy link
Collaborator

#pragma mark - 公共方法
+ (NSMutableArray *)properties
{
    MJExtensionSemaphoreCreate
    MJExtensionSemaphoreWait
    NSMutableArray *cachedProperties = [self propertyDictForKey:&MJCachedPropertiesKey][NSStringFromClass(self)];

    if (cachedProperties == nil) {
        if (cachedProperties == nil) {
            cachedProperties = [NSMutableArray array];
            
            [self mj_enumerateClasses:^(__unsafe_unretained Class c, BOOL *stop) {
                // 1.获得所有的成员变量
                unsigned int outCount = 0;
                objc_property_t *properties = class_copyPropertyList(c, &outCount);
                
                // 2.遍历每一个成员变量
                for (unsigned int i = 0; i<outCount; i++) {
                    MJProperty *property = [MJProperty cachedPropertyWithProperty:properties[i]];
                    // 过滤掉Foundation框架类里面的属性
                    if ([MJFoundation isClassFromFoundation:property.srcClass]) continue;
                    property.srcClass = c;
                    [property setOriginKey:[self propertyKey:property.name] forClass:self];
                    [property setObjectClassInArray:[self propertyObjectClassInArray:property.name] forClass:self];
                    [cachedProperties addObject:property];
                }
                
                // 3.释放内存
                free(properties);
            }];
            
            [self propertyDictForKey:&MJCachedPropertiesKey][NSStringFromClass(self)] = cachedProperties;
        }
    }
    MJExtensionSemaphoreSignal
    return cachedProperties;
}

@kinarobin
Copy link
Collaborator

@kobe1941 你改成这样的试一下?

@kobe1941
Copy link
Author

你把锁放到外围了,好的我试试看 @kinarob

@kinarobin
Copy link
Collaborator

@kobe1941 你项目这个崩溃比例高吗?

@kobe1941
Copy link
Author

@kinarob 比较低,用最新版本的MJExtension,目前只看到一个崩溃日志上报,继续观察

@kobe1941
Copy link
Author

@kinarob 你合并代码后,发新的版本,我后面直接集成新版本好了

@kinarobin
Copy link
Collaborator

@kobe1941 已经发布3.0.16的版本

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants