Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Basic Semaphore

52 views
Skip to first unread message

Horace Yu

unread,
Sep 18, 2001, 11:52:25 PM9/18/01
to
Hi,

I have the following basic semaphore question, for which I was not
able to find an answer in the VxWorks manual :

--> what happens if a task takes a sem which it has already taken, or if
a task gives a sem which has not been taken?

Thanks!!

Regards,
Horace

Manuel van den Berg

unread,
Sep 19, 2001, 5:48:34 AM9/19/01
to
This is definitely documented. Just take a look at the manual pages for
semLib, semMlib, semBlib and semClib. Behavior is defined as follows:

Mutex (semMlib semaphore) - Can be taken recursively by a task. For every
semTake, a corresponding semGive must be present. semGive can only be
done from the task that performed the semTake.

Counting & Binary semaphores - Are not sensitive as to which task performs
the semTake or semGive. Task 1 may perform a semTake, while task 2
performs
corresponding semGive.

For more info, read the manuals, it is all there !

Cheers,

Manuel

"Horace Yu" <hora...@sympatico.ca> wrote in message
news:3BA81679...@sympatico.ca...

Horace Yu

unread,
Sep 19, 2001, 9:12:55 AM9/19/01
to
Hi,

I am using a binary sem. I know it doesn't matter which task do the Take
or Give. But what happens if the same task tries to semTake a second time
without someone else semGive; or if the same task does a semGive without
someone else (or itself) semTake it?
Thanks again.

Regards,
Horace

joe durusau

unread,
Sep 19, 2001, 6:49:50 AM9/19/01
to
It depends on the exact situation. Example: For a binary semaphore,

If you try to take and the sem is empty, the task blocks for the time
specified in the semTake function call, or until some other task gives the
sem,
whichevewr comes first.

If you give the sem and it is already full, nothing happend. It remains
full.

There are other situations for counting semaphores, mutex semaphores, etc.

The details are in the reference manual, under the functions in question.

One caveat: make sure that you decide which type of sem you want.
There are manny variations on the theme available.

Speaking only for myself,

Joe Durusau

Manuel van den Berg

unread,
Sep 20, 2001, 5:49:08 AM9/20/01
to
This is in the manuals, just read them carefully.

"Horace Yu" <hora...@sympatico.ca> wrote in message

news:3BA899D7...@sympatico.ca...

0 new messages