3 ms·
maybe i'm a clown(i certainly haven't written any libraries). but with pthreads for example you you put the new()and free() into a wrapper around the function
by throwawayaway 12y ago
maybe i'm a clown(i certainly haven't written any libraries).
but with pthreads for example you you put the new()and free() into a wrapper around the function you want to call?
void wrapper()
{
new();
job();
free();
}
pthread_t thread;
int yes = 0;
pthread_create(&thread, NULL, wrapper, (void *) &yes);
- haberman 12y agoThat works if you are the application, or a framework that is in control of all thread creation. If you are just trying to be a thread-safe library though, you aren't at liberty to do that. For example, say someone wrote a thread-safe stack, like the article author. As the user of that thread-safe, lock-free stack, you don't want to put it in charge of all your threading, it's just one little library you're using.