capture a stack of calls and run it in a different thread


I need to write a logging api which does the actual logging on a seperate thread.

i.e. I have an application which wants to log some information. It calls my API and the api captures all the arguments etc and then hands that off to a seperate thread to be logged.

The logger api accepts variadic arguments and therefore my initial thoughts were to capture the whole call stack and somehow hand it to the thread whcih will do the logging.

I'm reasonable happy that I can capture the call stack. However I'm not sure how I'd pass this call stack off to another method.

I'm using g++ on linux and it may also have to work with Sun's CC v12 on solaris.

Any ideas.

You could capture a fixed amount of bytes on the call stack, but you have to copy all that memory even when it's not necessary and put it on a queue of some sort to pass it to the logging thread. Seems like a lot of work to get working, and quite inefficient.

I assume you're using a separate logging thread to make the logging API more efficient. It's quite probable that it's more efficient in this case to have the logging API extract the variadic parameters, convert them into a simpler representation (for example the string to be logged) and queue that.

Note also that a good logging API shouldn't block, so I'd advise a lock-free queue between the logging API and the logging thread.