Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/28/16 17:03:36 (8 years ago)
Author:
thasling
Message:

#2615:
implemented lock for timers, because if elapsed-method takes longer than the timer to elapse again, the method is called by another thread conccurently

Location:
branches/thasling/DistributedGA/DistributedGA.ContactServer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/thasling/DistributedGA/DistributedGA.ContactServer/ContactServiceImpl.cs

    r13924 r13943  
    1818
    1919    private Object logLock = new Object();
     20
     21    private Object timerLock = new Object();//if elapsed takes too long, another thread also enters the method
    2022
    2123    public ContactServiceImpl() {
     
    7880
    7981    private void CleanUpContactTable(object sender, ElapsedEventArgs e) {
    80       DateTime deadline = DateTime.Now;
    81       //collect items to remove
    82       List<PeerInfo> itemsToDelete = new List<PeerInfo>();
    83       foreach (PeerInfo pi in allPeers.Keys) {
    84         DateTime tmp;
    85         if (allPeers.TryGetValue(pi, out tmp)) {
    86           //if (tmp.AddHours(1f) < deadline)
    87           if (tmp.AddMinutes(1) < deadline)  //TODO
     82      lock (timerLock) {
     83        DateTime deadline = DateTime.Now;
     84        //collect items to remove
     85        List<PeerInfo> itemsToDelete = new List<PeerInfo>();
     86        foreach (PeerInfo pi in allPeers.Keys) {
     87          DateTime tmp;
     88          if (allPeers.TryGetValue(pi, out tmp)) {
     89            //if (tmp.AddHours(1f) < deadline)
     90            if (tmp.AddMinutes(1) < deadline)  //TODO
    8891                    {
    89             //if (tmp < deadline.AddHours(1f)) {
    90             itemsToDelete.Add(pi);
     92              //if (tmp < deadline.AddHours(1f)) {
     93              itemsToDelete.Add(pi);
     94            }
    9195          }
    9296        }
    93       }
    94       //remove items
    95       foreach (PeerInfo pi in itemsToDelete) {
    96         DateTime tmp;
    97         allPeers.TryRemove(pi, out tmp);
    98         Console.WriteLine(string.Format("Removed peer {0}:{1} from dictionary because last access was: {2}", pi.IpAddress, pi.Port, tmp));
     97        //remove items
     98        foreach (PeerInfo pi in itemsToDelete) {
     99          DateTime tmp;
     100          allPeers.TryRemove(pi, out tmp);
     101          Console.WriteLine(string.Format("Removed peer {0}:{1} from dictionary because last access was: {2}", pi.IpAddress, pi.Port, tmp));
     102        }
    99103      }
    100104    }
  • branches/thasling/DistributedGA/DistributedGA.ContactServer/DistributedGA.ContactServer.csproj

    r13524 r13943  
    5555  </ItemGroup>
    5656  <ItemGroup>
    57     <None Include="App.config" />
     57    <None Include="App.config">
     58      <SubType>Designer</SubType>
     59    </None>
    5860  </ItemGroup>
    5961  <ItemGroup>
Note: See TracChangeset for help on using the changeset viewer.