On Fri, 30 May 2008 15:27:12 PDT Skip Tavakkolian <[EMAIL PROTECTED]> wrote:
> i need to build a monte carlo simulator to model a system. i
> was first thinking of using libthread and channels, etc. but i'm
> wondering if newsqueak would be a better fit. has it been used
> for this?
Why Newsqueak? Why not roll your own simulation kernel?
Basically you need
new_thread(function, argument, stackksize);
condition = new_condition();
busy(how_many_time_units);
wait(condition);
signal(condition);
yield(); // may be
You do need stack switching code in asm or use setjmp/longjmp
for it but the rest is pretty easy. The scheduler is a
priority queue of (time-to-run,thread), each condition has a
list of waiter threads, busy(n) puts the current thread on
the schedule to run n time units in future, wait(cond) puts
the current thread on the waiter list of cond, signal(cond)
moves all waiter threads to the run-queue and yield()s etc.
This simulation kernel is likely to be more efficient than a
generic threads package. As an example, on a 1.5Ghz P4 (IBM
T42) per thread context switch time is about 56ns for 1000
threads, increasing to about 490ns for 100,000 threads.
You can use one or more threads to generate random events
with whatever probabilistic distribution you want.