Wednesday, March 21st 2018, 12:02am UTC+1

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to SEGGER Forum. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.



Date of registration: Sep 2nd 2010

Posts: 2


Thursday, September 2nd 2010, 3:41pm

Deletion of Semaphore which is attached to a terminated Task leads to OS Error

I have the following scenario:
- Following sequence is executed in Task X:
- Create Semaphore S (with OS_CreateSema()) with initial value of 0
- Create Task A and hand over Semaphore S
- Allow startup of Task A by using OS_Delay()
- Task A approaches OS_WaitCSem() and hence waits for the release of Semaphore S (as the init value has been set to 0)
- Task X terminates Task A by using OS_Terminate()
- Task X deletes Semaphore S ---> this leads to OS error because the semaphore was used by the already terminated Task A

How can I avoid that situation but still making sure that all resources are freed up at the end?

Date of registration: Dec 20th 2007

Posts: 26


Thursday, September 9th 2010, 11:58am

terminating a task by a call of OS_Terminate() should release all "waitable" objects the task is waiting at.
The wait list of the semaphore should be empty after termination of the waiting task.
I verified this by a simple modification of our "Start2Tasks" sample from embOS:
static OS_CSEMA _CSema;

static void HPTask(void) {
OS_CreateCSema(&_CSema, 0);
while (1) {
OS_Delay (10);

static void LPTask(void) {
unsigned char RunFirst;

RunFirst = 1;
while (1) {
if (RunFirst) {
RunFirst = 0;
OS_Delay (50);

Which embOS version are you using?
Which compiler?
Which CPU?



Date of registration: Sep 2nd 2010

Posts: 2


Friday, September 10th 2010, 4:23pm

Thank you for the code snippet. That helped me to understand the issue. Issue is solved for me. Thank you!