question

Axel Kohonen avatar image
0 Likes"
Axel Kohonen asked Matt Long commented

How should I give the resource reference to the release resource activity if I do it in code?

Hi,

How should one give the resource to free to the release resource activity so that the resource is released? For the aquire resource the resource can be given with

return getactivity(processFlow, resourceName);

but that does not seem to work with release resource. I would like to not use the picklist option Label: resource. What is FlexSim doing behind the scenes here? I am curios as the manual only states that

"The return value of this field should be a label on a token where an Acquire Resource activity assigned the acquired resource to."

but if I e.g. copy the resource label using a "create tokens" activity and use independent tokens in the sub-process then I cannot release the resource from the sub flow. It seems that the only way to do this is to create tokens as child nodes and allow access to the parent labels where the resource was reserved. Is the resource reservation somehow connected to the parent label or can the resource be freed from anywhere if we have a reference to the resource?

The case: I reserve a resource in the main process flow. When a certain time has elapsed the main token can continue execution, but the resource should not be released until is has been cleaned. Thus the main process flow creates a token to a sub flow where the cleaning is done and when ready the resource should be released. My problem is that the resource is not always on the "resource" label as I have multiple resources that I store in labels with different names, but I would like to use the same cleaning sub flow for any resource that is to be cleaned and then released.

A possible solution is to release the resource in the main process flow after the sub flow has been called. In the sub flow I acquire the resource again and then free it at the end of the sub flow. This requires extra acquiring and releasing and I need to make sure with queries in the resources and a label on the token that no one else gets to acquire the resource before the cleaning is done.

Any pointers on this?

Thank you!

Kind regards,

Axel

FlexSim 16.2.1
process flowrelease resource
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Matt Long avatar image
1 Like"
Matt Long answered Matt Long commented

You cannot copy the label and then call Release Resource on the copied label. The information stored on the token that associates the shared asset with the label is not actually stored on the label, but on the token that acquired the resource. So when the documentations says:

"The return value of this field should be a label on a token where an Acquire Resource activity assigned the acquired resource to."

it HAS to be the label that the Acquire activity assigned to. It works on the child because it is referencing back to the original label that was assigned. If you want to do it on an Indpendent token, you don't want to copy the label, instead, you want to assign a label to the created token that points to the resource label or to the owner token. The code in the Release Resource field would then be:

label(token, "resourceRef");
or
label(getlabel(token, "ownerToken"), "resource");

So what FlexSim is doing 'behind the scenes' when you say Label: resource, is calling label(token, "resource") as opposed to getlabel(token, "resource").

The documentation could probably be a bit more explicit on what needs to be passed into this field. I also realized that the two pick options in that field don't actually work. They should be using label() commands not getlabel().

· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Axel Kohonen avatar image Axel Kohonen commented ·

Hi @Matt Long

Thank you! That explains it. Would be great if you could update the documentation. For those that want to know how it is done, find the model that works with independent tokens here. I set the reference to the original token label into the label that I create on the independent token.

tokenreleasetest-workingwithindependenttoken.fsm

To clarify still, as one references the original token label can it ever happen that we get problems if the original token is destroyed? In my test model below it seems that we do not get an exception in release resource even if the original token has been destroyed by the sink and the resource has been released before we get to the release resource activity.

tokenreleasetest-workingwithindependenttoken-sinkd.fsm

Also, if you can change your comment to an answer I would be happy to accept it.

Axel

0 Likes 0 ·
Matt Long avatar image Matt Long Axel Kohonen commented ·

The Release activity was designed to not thrown any exceptions or make any complaints if you pass it a label that doesn't have an associated Resource. This allows you to send tokens that have and have not acquired a resource down the same set of activities, or to use the Max Wait Timer to release a token without acquiring a resource and not having to use Decides to bypass the Release.

And of course on the Sink activity you can check whether Shared Assets are deallocated or not.

1 Like 1 ·
Matthew Gillespie avatar image
3 Likes"
Matthew Gillespie answered Matt Long converted comment to answer

The confusion here is that we're using the word Resource to mean two different things

1. The shared asset

2. The thing acquired from the shared asset.

The Acquire Resource activity has a Resource Reference field which expects a reference to the Resource shared asset. The acquire activity then goes to that shared asset and asks for one of its things (group member, a number, etc). The thing you acquire is assigned to the label you specify. Also on that label is recorded some information about how that thing was acquired including a reference back to the Resource shared asset.

The Release activity only cares about the thing you acquired (more specifically, the label where that thing was assigned). The Release activity then uses that label and its reference back to the shared asset to tell the shared asset that the thing is available and to clean up the information on the label.

So in the end you have to give the Release activity the label where the thing from the shared asset was assigned when acquired. If you need to do this on an independent token you should assign a label to the new independent token when you create it so it know how to get to the resource label.

I don't completely understand your example at the end. You might need to provide a sample model that shows what you're trying to do.

· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Axel Kohonen avatar image Axel Kohonen commented ·

Hi @Matthew Gillespie

Thank you for the clarification! To me it seems that it is not enough to give a copy of the label that points to the resource, but you have to give the actual original resource label to the Release the resource activity. See the two attached model files. In the first one tokenreleasetest.fsm the subflow token is created as a child token of the main process token with read/write rights and release resource gets the token of the parent if I understand it correctly.

In the second model tokenreleasetest-notworking.fsm the sub flow token is created as an independent token and the labels are copied to it from the parent. In this case the release resource is not able to free the resource although it has the copy of the correct label.

The reason I want to use this is that I have a process flow where I would like to use the same sub flow for releasing the resources even though I have used different resource label names when acquiring the resource. As I have used different label names I cannot create the tokens to the sub flow as child tokens as I did not find a way to tell process flow what the name of the resource label is in a particular case.

I hope this clarifies the issue.

Thank you!

Axel

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.