Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Um...

Name: Anonymous 2008-10-18 15:04

Why doesn't malloc just wait until enough memory becomes free instead of returning an error if there isn't enough available?

Name: Anonymous 2008-10-18 15:08

>>1
main() {
    fork();
    void *a = malloc( 1024 );
    void *b = malloc( 1024 );
    free( b );
    free( a );
}

Assuming there's only 2048 bytes of memory available, can you see a fairly obvious deadlock? It's easier to have it remain synchronous. If you're really serious about it,

void *awesum_malloc( size_t s ) {
    void *blob = malloc( s );
    if ( blob )
        return blob;
    sleep( 10 );
    return awesum_malloc( s );
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List