previous | start | next

Life Time of Thread Arguments

Four approaches

  1. Copy all argumnets to the thread's stack: not supported!

    pthread initial functions only take 1 argument.

  2. Pass a pointer to local storage containing the arguments:

    Ok if we are certain this storage doesn't go out of scope until the thread is finished with it!

  3. Pass a pointer to static or global storage containing the arguments:

    Works only if only one thread at a time is using the storage.

  4. Pass a pointer to dynamically allocated storage containing the arguments.

    This works provided the storage can be released (free()) when (and only when) the thread is finished with it.



previous | start | next