[M3devel] Per thread data

Mika Nystrom mika at async.async.caltech.edu
Tue Sep 14 06:55:04 CEST 2010


Darko writes:
>I need to have certain data structures allocated on a per thread basis. =
>Right now I'm thinking of using the thread id from ThreadF.MyId() to =
>index a list. Is there a better, more portable way of allocating on a =
>per-thread basis?
>
>Cheers,
>Darko.

In my experience what you suggest works just fine (remember to lock the
doors, though!)  But you can get disappointing performance on some thread
implementations (ones that involve switching into supervisor mode more
than necessary when accessing pthread structures).

Generally speaking I avoid needing per-thread structures as much as possible
and instead put what you need in the Closure and then pass pointers around.
Of course you can mix the methods for a compromise between speed and
cluttered code...

I think what you want is also not a list but a Table.

      Mika



More information about the M3devel mailing list