[ 
https://issues.apache.org/jira/browse/IGNITE-21926?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yexiaowei updated IGNITE-21926:
-------------------------------
    Description: 
I noticed that GridCacheLockImpl and GridCacheSemaphoreImpl can cause 
deadlocks. Because their model is similar to the following
{code:java}
Sync sync;
​
void init() {
  sync = getSync();
}
​
void onUpdate(val) {
  if(sync == null) {
    return;
  }
  update(sync);
}
{code}

If init and onUpdate occur at the same time, update may be missed and lagging 
data may be obtained. The fix I gave is similar to:
{code:java}
Sync sync;
boolean flag = false;
​
void init() {
  do {
    flag = false;
    s = getSync();
  } while(flag);
}
​
void onUpdate(val) {
  if(sync == null) {
    flag = true;
    return;
  }
  update(sync);
}
{code}

  was:
I noticed that GridCacheLockImpl and GridCacheSemaphoreImpl can cause 
deadlocks. Because their model is similar to the following
Sync sync;
​
void init() {
  sync = getSync();
}
​
void onUpdate(val) {
  if(sync == null) {
    return;
  }
  update(sync);
}
If init and onUpdate occur at the same time, update may be missed and lagging 
data may be obtained. The fix I gave is similar to:
Sync sync;
boolean flag = false;
​
void init() {
  do {
    flag = false;
    s = getSync();
  } while(flag);
}
​
void onUpdate(val) {
  if(sync == null) {
    flag = true;
    return;
  }
  update(sync);
}


> The status of GridCacheLockImpl and GridCacheSemaphoreImpl may be inconsistent
> ------------------------------------------------------------------------------
>
>                 Key: IGNITE-21926
>                 URL: https://issues.apache.org/jira/browse/IGNITE-21926
>             Project: Ignite
>          Issue Type: Bug
>          Components: data structures
>            Reporter: yexiaowei
>            Priority: Major
>
> I noticed that GridCacheLockImpl and GridCacheSemaphoreImpl can cause 
> deadlocks. Because their model is similar to the following
> {code:java}
> Sync sync;
> ​
> void init() {
>   sync = getSync();
> }
> ​
> void onUpdate(val) {
>   if(sync == null) {
>     return;
>   }
>   update(sync);
> }
> {code}
> If init and onUpdate occur at the same time, update may be missed and lagging 
> data may be obtained. The fix I gave is similar to:
> {code:java}
> Sync sync;
> boolean flag = false;
> ​
> void init() {
>   do {
>     flag = false;
>     s = getSync();
>   } while(flag);
> }
> ​
> void onUpdate(val) {
>   if(sync == null) {
>     flag = true;
>     return;
>   }
>   update(sync);
> }
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to