> For an ordinary binary semaphore, a
> task attempting to synchronize to an
> external event creates an empty
> semaphore....A second task which
> controls the synchronization event
> gives the semaphore when it is no
> longer needed.
#include "vxWorks.h"
#include "semLib.h"
#define T_PRIORITY 50
SEM_ID syncExampleSem; // named semaphore object
void initialize (void)
{
// set up FIFO queue with emtpy binary semaphore
syncSem = semBCreate (SEM_Q_FIFO, SEM_EMPTY);
// create task1
taskSpawn ("task1", T_PRIORITY, 0, 10000, task1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
// create task2
taskSpawn ("task2", T_PRIORITY, 0, 10000, task2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
void task1 (void)
{
// stay here until semaphore becomes available
semTake (syncExampleSem, WAIT_FOREVER);
// do something
}
void task2 (void)
{
// do something
// now let task1 execute
semGive (synExampleSem);
}
My question is why don't I see the first task creating the empty semaphore, as described? (It looks like it is just done "generically" in the main function?) **"a task attempting to synchronize to an external event creates an empty semaphore".**
Also, I don't really see how the second task is "controlling" the synchronization?
Thank you.
See: Example of synchronization through binary semaphore
http://www.cross-comp.com/instr/pages/embedded/VxWorksTutorial.aspx#VxWorks%20Programming
以上就是What task is supposed to be created in this example?的详细内容,更多请关注web前端其它相关文章!