thread slinger  0.1
zero copy messaging between threads
 All Classes Functions Variables Enumerations Enumerator Pages
threadslinger user's API documentation

This is the user's manual for the threadslinger API.Interesting classes:

struct myMessage : public thread_slinger_message
{
int a; // some field
int b; // some other field
};
thread_slinger_pool<myMessage,5> p;
typedef thread_slinger_queue<myMessage> myMsgQ;
myMsgQ q;
myMsgQ q2;
void * t3( void * dummy ) {
uintptr_t val = (uintptr_t) dummy;
while (1) {
myMessage * m = p.alloc(random()%5000);
if (m) {
if (val == 0)
q.enqueue(m);
else
q2.enqueue(m);
if (val == 0)
printf("+");
else
printf("=");
} else {
if (val == 0)
printf("-");
else
printf("_");
}
fflush(stdout);
usleep(random()%30000);
}
return NULL;
}
void * t4(void * dummy) {
myMsgQ * qs[2];
qs[0] = &q;
qs[1] = &q2;
while (1) {
int which;
myMessage * m = myMsgQ::dequeue(qs,2,(int)(random()%1000),&which);
if (m) {
if (which == 0)
printf(".");
else
printf(",");
p.release(m);
} else {
printf("!");
}
fflush(stdout);
usleep(random()%10000);
}
return NULL;
}
int main() {
pthread_t id;
pthread_create( &id, NULL, t3, (void*) 0 );
pthread_create( &id, NULL, t3, (void*) 1 );
pthread_create( &id, NULL, t4, (void*) 0 );
pthread_join(id,NULL);
return 0;
}