How to awake a process waiting for a semaphore?

Garcia Jérémie GARCIAJ at
Mon Jun 27 23:59:01 EST 2005

Hi everybody,
as the subject of this mpail tells, I'd like to be able to interrupt a task that
is waiting for a semaphore to be free.
Indeed I use "down_interruptible()" and I'd like to be able to tell to the task
after a period of time : "give up, awake and do something else".
I tried this piece of code in a kernel module to test this, but obviously that 
doesn't work (I tried 2 ways but both failed)  : 

struct semaphore * testSem;

void myAlert(unsigned long data)
  char *msg = "TIMEOUT!\n";
  task_t * myTask = (task_t *)data;

  printk("Current task state : %d",myTask->state);

  // First Test
  wake_up_process((task_t *)data);

  // Second Test
  //myTask->state = TASK_RUNNING

int test(void)
  int ret_val,state,timeout=500;
  struct timer_list myTimer;
  testSem = (struct semaphore *)kmalloc(sizeof(struct semaphore),GFP_ATOMIC);
  state = current->state;
  printk("Current task state: %d\n",state);

  myTimer.expires = jiffies + timeout; = (unsigned long) current;
  myTimer.function = myAlert; = (unsigned long) current;

  // That will get the task to sleep for sure

  return 0;

More information about the Linuxppc-dev mailing list