The problem is if i call shcedule() on it's own, the current process will not guaranteed abort or in other words, context switch is not quaranteed 100%. I did a test on it.
In order to make the current process switch to another one, a definite solution is to set the current state to TASK_INTERRUPTIBLE or TASK_UNINTERRUPTIBLE. You r right about this. Problem is once the process is change from TASK_RUNNING -> TASK_INTERRUPTIBLE, how can we wake up the process unless, a signal (from kill) or a hard interrupt happens. So, that means, this method of context switching is not workable.
For schedule_timeout , it works perfectly with TASK_INTERRUPTIBLE set. Because, this function actually intialzie a timer IRQ and an interrupt is triggered when time out thus, waking up the task.
I actually want to implement a time condition wait while checking the semaphore try lock. I do not want to use the down semaphore function which is blocking. I want to use a try lock (non -blocking semaphore) and then, check the timestamp. If the time stamp > time out , i will exit the loop. ( Implementing semaphoreWait with time out in linux).
Does anyone has the answer to this?