If a resource is locked using semaphore by taskA , and if any other task accessess the resource (unprotected access)without locking it then will the task go in waiting state ? Or it is an code error in RTOS system.
taskA() //low priority
{
SemLock(A);
A=10;
A=A+1;
SemmUnlock(A);
}
taskB() //high priority
{
A=20;
}
if taskA is running and if taskB arrives then will taskB wait in a RTOS system?
No, if the task without the mutex (semaphore) does not attempt to get The mutex then it will not block before using the resource. The RTOS does not have any special awareness of which tasks are using a resource. Each task must get the mutex before using the resource in order to protect the resource from potentially multiple corrupting accesses.
In your example task B could preempt task A and corrupt the resource while task A has the semaphore locked.