server_heap_is_busy()

int server_heap_is_busy(server_heap_t *heap);

This function polls the heap busy status without waiting.

Returns 1 if the heap is 'busy', meaning there are still units originating from this heap with a positive reference count.

0 is returned when the heap is not busy.

This can be used to synchronize threads that share a heap for communication use. A producer thread may be used to allocate units on the heap, and as a result would be the only source of new allocations. Consumer threads would receive the allocated units and unref each when finished "consuming".

By polling the heap periodically in your producer, you seize all new allocations and wait for all consumption to finish. This is typical of shutdown procedures, but in general it is not appropriate to wait for threads to finish things so use in practice expected to be rare.

This function is not intended to be used where efficiency is important, otherwise it would be designed to wait rather than poll.



2007-12-06