ST/V, is this a safe practice? 
Author Message
 ST/V, is this a safe practice?

I am using ST/V version 2 but am interested in answers for other Smalltalks
too.

Is it safe to add to an SortedCollection while processing its members
via do:  ???   In my case the added new member will always sort into
a position 'later' than the member currently being processed.

I am using SortedCollections as event queues.  Member objects are events that
get ordered according to an instance variable that contains the event's
scheduled time. This is in a simulation.  There are no real-time considerations
and I don't need to make events occur at their scheduled time, I just need to
make sure they occur in the scheduled sequence.  This is accomplished by
something like:

   eventQueue do: { :event | event occur }

Please excuse the curly braces instead of square brackets (keyboard issue
here).  This approach works wonderfully, so far ...

Sometimes events occur and discover that they need a resource that is currently
busy.  They react to that by re-queuing themselves for a later time.  Actually,
they change their scheduled_time instance var and return an indication telling
the sending method that the event has a new time and should be re-queued:

   eventQueue do: { :event | (event occur) ifTrue: {eventQueue add: event} }

This is WayCool, but only if it is reliable.

I have not been able to read the sourcecode for SortedCollection's do: and add:
with confidence that I KNOW what happens.

I do see some things that make me worry.  In particular, the process of adding
to a Sorted Collection can sometimes mean making a whole new copy of its
'contents' Collection.  Also, the first item in the SortedCollection need not
be the first item of its 'contents' collection.   I am worried about loosing my
position in the collection.

As I said, it appears to work but just to be safe I have recently started
oversizing the eventQueue so that it should never need to be re-sized.
That is not killing me right now because the event queue is not large, I know
the initial size when the queue is allocated and can start it up using new:
rather than new and I have can track re-queuing activity and know about what to
expect for a safe size.

Still, it would be nice to not worry about all that and it would be nice
to use this technique when the cost of oversizing the queue is unacceptable.

Jim Colten



Mon, 19 Jan 1998 03:00:00 GMT  
 ST/V, is this a safe practice?

Quote:

>I am using ST/V version 2 but am interested in answers for other Smalltalks
>too.

>Is it safe to add to an SortedCollection while processing its members
>via do:  ???   In my case the added new member will always sort into
>a position 'later' than the member currently being processed.

 I wouldn't do this, because it's not defined, what can happen.

Quote:

>   eventQueue do: { :event | (event occur) ifTrue: {eventQueue add: event} }

eventQueue do: { :event | (event occur) ifTrue: {eventQueue2 add: event} }
eventQueue addAll: eventQueue2

or

eventQueue copy do: { :event | (event occur) ifTrue: {eventQueue add: event} }

(you get a light copy of the collection. Therefore the possible solution
should look at the average size of eventQueue)

 Marten

--

           "I do not respect people who do not respect people."



Tue, 20 Jan 1998 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. ST vs Java vs ST vs ....

2. Practice safe hexing - how to avoid future script viruses

3. Clock Problem (VA ST vs. Dolphin ST)

4. Classes - instance/class, methods/members, inheritance and be st practices

5. Comparison: ST-80 vs. ST-V

6. ST-80/OS/2 vs. ST-80/Windows

7. Am I Safe?

8. gnu smalltalk vs st/v vs digitalk

9. What is good ( as vs typical ) practice?

10. Safe-TCL vs. Sockets

11. How safe is $SAFE=4?

12. C++ STL Containers vs. ST Collections

 

 
Powered by phpBB® Forum Software