红鱼儿

kbmMW使android App无法退出

升级到Delphi 11.1+kbmMW 5.19,编译后的项目在android平台上无法正常退出,这种情况下,再重进App,会卡死在启动界面,浪费N多脑细胞,发现是

kbmMWClientConnectionPool1造成的结果,他无法完成释放过程,跟踪代码发现执行StopScheduling方法时卡死,查看这个方法,原来就一句,执行线程对象的Pause方法,进一步查看Pause方法,发现调用逻辑使用FLock.BeginWrite进行加锁,而且嵌套使用的,类似下面的代码:

Flock.BeginWrite;
  Flock.BeginWrite;
  ...
  Flock.EndWrite;
Flock.EndWrite;

在执行Flock.BeginWrite卡死了!功力不够,所以先跳过Pause的执行,修改成下面这个,暂时避免这个问题:

procedure TkbmMWPooledDatasetRefreshScheduler.StopScheduling;
begin
    if FThread.IsStarted then// add by 红鱼儿
       FThread.Pause;
end;

现在app可以正常退出了。已经将问题反应给作者,等修复。

具体地址在这里:https://components4developers.blog/forums/topic/aaaaa/#post-56413

进一步查看是TkbmMWMREWLock锁产生的这个问题,编译变量是默认的:

// ===========================================================================
// Performance settings.
// Remove the // from the following lines to enable specific performance
// optimizations
// ===========================================================================
//{$DEFINE KBMMW_OPTIMIZED_MEMORYSTREAM}    // If to use an optimized memory stream handling.
//{$DEFINE KBMMW_SUPPORT_MRWSLOCK}          // If to use Embarcadero Multiple Reader Exclusive Writer lock.
{$DEFINE KBMMW_SUPPORT_FASTMRWSLOCK}      // If to use native very fast Multiple Reader Exclusive Writer lock.
{$DEFINE KBMMW_SUPPORT_FASTEVENT}         // If to use native very fast event mechanism.
{$DEFINE KBMMW_SUPPORT_LIGHTWEIGHTEVENT}  // If to use Embarcadero lightweight event mechanism.

试着使用KBMMW_SUPPORT_MRWSLOCK编译项目,无法通过,因为源代码需要进一步修改,放弃测试。

kbmMW支持多种锁的,等作者处理吧。

开发环境:Delphi 10.4.2 Delphi 11.1及kbmMW 5.18,kbmMW 5.19都存在这个问题。

 

posted on 2022-04-12 20:13  红鱼儿  阅读(224)  评论(0编辑  收藏  举报