Semaphore in Timer Service task

michaeln32 wrote on Sunday, July 01, 2018:


I created function1 and put it into Timer Service task.

OnlyTimer Service task can call and run function1.

I created functions2 that all other tasks in the system can call and run.

Both in function1 and function2 access (read and write) global data A.

I protect global data A with semaphore (mutex).

In this case Timer service task can be blocked on the semaphore waiting to access global data A.

Can Timer service task be blocked on semaphore ?

Is it wrong to put Timer service task into block ?

michaeln32 wrote on Sunday, July 01, 2018:


richard_damon wrote on Sunday, July 01, 2018:

Timer callback functions are not supposed to block ( at the bottom) so having function1 actually block to get access can cause problems. It could check the semaphore with a zero block time to decide if it can use the data or not.
This doesn’t mean that the global data doesn’t need protection, depending on the nature of the accesses, you may well still need some form of protection.

If the updating action is short enough, you could use a critical section to protect it instead.