Skip to contents

This brick encapsulates a delayed release: the arrival releases the resource and continues its way immediately, but the resource is busy for an additional period of time.

Usage

delayed_release(
  .trj,
  resource,
  task,
  amount = 1,
  preemptive = FALSE,
  mon_all = FALSE
)

delayed_release_selected(
  .trj,
  task,
  amount = 1,
  preemptive = FALSE,
  mon_all = FALSE
)

Arguments

.trj

the trajectory object.

resource

the name of the resource.

task

the timeout duration supplied by either passing a numeric or a callable object (a function) which must return a numeric (negative values are automatically coerced to positive).

amount

the amount to seize/release, accepts either a numeric or a callable object (a function) which must return a numeric.

preemptive

whether arrivals in the server can be preempted or not based on seize priorities.

mon_all

if TRUE, get_mon_arrivals will show one line per clone.

Value

Returns the following chain of activities: clone

> synchronize (see examples below).

Examples

## These are equivalent for a non-preemptive resource:
trajectory() %>%
  delayed_release("res1", 5, 1)
#> trajectory: anonymous, 6 activities
#> { Activity: Clone        | n: 2 }
#>   Fork 1, continue,  trajectory: anonymous, 2 activities
#>   { Activity: SetCapacity  | resource: res1, value: -1, mod: + }
#>   { Activity: Release      | resource: res1, amount: 1 }
#>   Fork 2, continue,  trajectory: anonymous, 2 activities
#>   { Activity: Timeout      | delay: 5 }
#>   { Activity: SetCapacity  | resource: res1, value: 1, mod: + }
#> { Activity: Synchronize  | wait: 0 }

trajectory() %>%
  clone(
    2,
    trajectory() %>%
      set_capacity("res1", -1, mod="+") %>%
      release("res1", 1),
    trajectory() %>%
      timeout(5) %>%
      set_capacity("res1", 1, mod="+")
  ) %>%
  synchronize(wait=FALSE)
#> trajectory: anonymous, 6 activities
#> { Activity: Clone        | n: 2 }
#>   Fork 1, continue,  trajectory: anonymous, 2 activities
#>   { Activity: SetCapacity  | resource: res1, value: -1, mod: + }
#>   { Activity: Release      | resource: res1, amount: 1 }
#>   Fork 2, continue,  trajectory: anonymous, 2 activities
#>   { Activity: Timeout      | delay: 5 }
#>   { Activity: SetCapacity  | resource: res1, value: 1, mod: + }
#> { Activity: Synchronize  | wait: 0 }

## These are equivalent for a preemptive resource:
trajectory() %>%
  delayed_release("res2", 5, 1, preemptive=TRUE)
#> trajectory: anonymous, 7 activities
#> { Activity: Clone        | n: 2 }
#>   Fork 1, continue,  trajectory: anonymous, 1 activities
#>   { Activity: Release      | resource: res2, amount: 1 }
#>   Fork 2, continue,  trajectory: anonymous, 4 activities
#>   { Activity: SetPrior     | values: [2147483647, 2147483647, 0], mod: N }
#>   { Activity: Seize        | resource: res2, amount: 1 }
#>   { Activity: Timeout      | delay: 5 }
#>   { Activity: Release      | resource: res2, amount: 1 }
#> { Activity: Synchronize  | wait: 0 }

trajectory() %>%
  clone(
    2,
    trajectory() %>%
      release("res2", 1),
    trajectory() %>%
      set_prioritization(c(rep(.Machine$integer.max, 2), 0)) %>%
      seize("res2", 1) %>%
      timeout(5) %>%
      release("res2", 1)
  ) %>%
  synchronize(wait=FALSE)
#> trajectory: anonymous, 7 activities
#> { Activity: Clone        | n: 2 }
#>   Fork 1, continue,  trajectory: anonymous, 1 activities
#>   { Activity: Release      | resource: res2, amount: 1 }
#>   Fork 2, continue,  trajectory: anonymous, 4 activities
#>   { Activity: SetPrior     | values: [2147483647, 2147483647, 0], mod: N }
#>   { Activity: Seize        | resource: res2, amount: 1 }
#>   { Activity: Timeout      | delay: 5 }
#>   { Activity: Release      | resource: res2, amount: 1 }
#> { Activity: Synchronize  | wait: 0 }