Today's Question:  What does your personal desk look like?        GIVE A SHOUT

SEARCH KEYWORD -- Smuggle



  Smuggling data in pointers

While reading up on The ABA Problem I came across a fantastic hack.  The ABA problem, in a nutshell, results from the inability to atomically access both a pointer and a "marked" bit at the same time (read the wikipedia page).  One fun, but very hackish solution is to "smuggle" data in a pointer.  Example:#include "stdio.h"void * smuggle(void * ptr, int value){  return (void *)( (long long)ptr | (value & 3) );}int recoverData(void * ptr){  return (long long)ptr &...

   C,Pointer,Bit,Data,Atomic,Smuggle     2011-11-14 08:15:59