Is this function pure?

Nathan Reed nathaniel.reed at gmail.com
Wed Sep 19 13:17:41 PDT 2007


Bill Baxter wrote:
> On the other hand the support for concurrency may consist of little more 
> than a global mutex.  That means that the performance benefits of 
> launching multiple threads might not be so great since they'll all just 
> end up in a queued waiting for their turn to malloc.
> 
> I have no idea what they do in practice though.  Do typical malloc 
> systems actually allow simultaneous allocations in multiple threads?
> 
> --bb

On a multicore system the allocator might conceivably have a heap for 
each core or something like that.

However, even if this is not the case, allocation in a garbage-collected 
language is very quick and the mutex would only need to be held for the 
duration of the allocation.

With a pure function that does some allocation and then a bunch of 
computation, all the computations could proceed in parallel once each 
thread's memory had been allocated.  Synchronized allocations certainly 
need not negate the benefits of parallelism.

Thanks,
Nathan Reed



More information about the Digitalmars-d mailing list