Re: Multitasking 2 Problem

new topic     » goto parent     » topic index » view thread      » older message » newer message

Al Getz wrote:
> After trying the new release i noticed that the task id numbers keep
> rising, even for the same task, when the task is created a second or
> more times...
> 
>   taskid=task_create(..)
> 
> creates say taskid=1, then after the task ends normally if it is
> created a second time taskid=2, then after that ends a third time
> produces taskid=3, etc.

Yes. You can create thousands of tasks that all simultaneously
run the same routine. These are all different tasks with different
task id's.

> I dont have any problem with using different numbers each time, but
> because they are continuously rising this means eventually the task id
> could reach max integer and the next create would cause a crash?
> Unless of course at some limit the numbers start over again?

When the task id reaches 1e14 (much bigger than an integer), 
I start over at 1 again, being careful not to issue the 
same id as one that is still in use. Task id's are atoms, 
not just integers. Somewhere beyond 1e14 is the point where 
adding 1 to a number gives you the same number.

To be squeaky clean, and avoid ever recycling ids, I considered 
making task id's sequences, which would slowly grow in length, 
so after reaching 1e14 I could just add another element to the 
sequence and start over. This would really make it unnecessary 
to ever recycle ids. However I often have to compare task id's 
against an internal list, and atoms would be faster. Probably no 
one will ever exceed 1e14, and if you do, recycling will happen, 
not a crash. The only theoretical problem is if you are  
checking the status of a task that died and had its id recycled
into a new task. You might think the original task was still running.

Given a machine 1000x faster than the PC's we have today, you might
be able to create 1e9 tasks per second if you did little else.
Then it would take 1e5 seconds (more than a day) to reach the 
point where recycling starts. I just tested now. I can increase 
the limit from 1e14 to 9e15. That's 90x more capacity. You'd need more
than 3 months. I guess I'll do that. (There's no point in 
performing arithmetic on a task id. It's just an identifier.)
On Linux/Unix etc. I think they start recycling process id's at
65000 or so.

Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu