[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: LuaTask needs your help
- From: Duck <duck@...>
- Date: Sun, 8 Jul 2007 18:53:06 +1000 (EST)
It seems to work across TASK_SLOTS_STEP boundaries when I use the test
code I had before. I tried creating 10 simultanous tasks, then 20, 40, 80,
160, 320 -- all good!
However, I can't create more than 509 tasks, i.e. 510 in total, including
the "_main_".
When I call task.create() for the 510th time, I get error -3 (can't create
message queue). This happens with PTHREAD_STACK_SIZE set to 1m or to 2m.
With the default PTHREAD_STACK_SIZE of 8m I get error -4 (can't create os
thread) at the 383rd task, presumably because I have exhausted all 3g of
virtual memory at that point.
Note that this isn't a new problem -- it exists with the 1.6.1 code as
well. I didn't realise it before because the segfault after
(TASK_SLOT_STEP-1) calls to task.create() got in the way :-) I just went
back to 1.6.1 and compiled with TASK_SLOT_STEP set to 600 in order to see
what happens: you get err -3 from the 510th call to task.create().
About the code itself, I have two suggestions.
Firstly, when you allocate space for the TASK_ENTRYs themselves (not the
list of pointers to TASK_ENTRYs), you don't check the return value of
malloc() for NULL.
Secondly, I'd strongly suggest factoring the actual malloc/realloc code
out into a function so it appears only once. At the moment you are
repeating code (except for a malloc() versus a realloc() -- and realloc()
behaves like malloc() when you feed it NULL). This means there are two
places to introduce errors or discrepancies.
My 2c.