Skip to content

synchronize() not work as expected #275

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

Closed
vohai611 opened this issue Mar 4, 2022 · 3 comments
Closed

synchronize() not work as expected #275

vohai611 opened this issue Mar 4, 2022 · 3 comments

Comments

@vohai611
Copy link

vohai611 commented Mar 4, 2022

library(simmer)
end = trajectory() %>% 
  synchronize(wait = FALSE) %>% 
  log_('leave')

p = trajectory() %>% 
  clone(n = 2,
        trajectory() %>% renege_in(t = 1, out = trajectory() %>% 
                                     join(end) ) %>% timeout(5) ,
        trajectory() %>% timeout(3) %>%
          join(end)) 

simmer() %>% 
  add_generator("p", p, distribution = at(c(1))) %>% 
  run(until = 10)
#> 2: p0: leave
#> 4: p0: leave
#> simmer environment: anonymous | now: 4 | next: 
#> { Monitor: in memory }
#> { Source: p | monitored: 1 | n_generated: 1 }

Created on 2022-03-04 by the reprex package (v2.0.1)

I expect that with wait=FALSE, only the first arrival can reach log_("leave").
Anyway, thank you guys for an amazing pacakges!

@Enchufa2
Copy link
Member

Enchufa2 commented Mar 4, 2022

Well, it is kind of expected. This trajectory is equivalent to the one above:

p = trajectory() %>% 
  clone(
    n = 2,
    trajectory() %>%
      renege_in(
        t = 1, out = trajectory() %>%
          synchronize(wait = FALSE) %>% 
          log_('leave')) %>%
      timeout(5),
    trajectory() %>%
      timeout(3) %>%
      synchronize(wait = FALSE) %>%
      log_('leave')
  ) 

Note what I did: I just replaced the joins with the part they are copying. Removing the renege_in, for better clarity:

p = trajectory() %>% 
  clone(
    n = 2,
    trajectory() %>%
      timeout(1) %>%
      synchronize(wait = FALSE) %>% 
      log_('leave'),
    trajectory() %>%
      timeout(3) %>%
      synchronize(wait = FALSE) %>%
      log_('leave')
  ) 

In essence, there are two distinct synchronize activities, and they are not aware of each other, so arrivals cannot be synchronized.

@vohai611
Copy link
Author

vohai611 commented Mar 4, 2022

Oh I see. Thank you!

@vohai611 vohai611 closed this as completed Mar 4, 2022
@Enchufa2
Copy link
Member

Enchufa2 commented Mar 4, 2022

Let me explore the possibility of setting a global storage for sync activities. Otherwise, I see no way of reneging and synchronizing.

@Enchufa2 Enchufa2 reopened this Mar 4, 2022
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