/* includes */
#include "vxWorks.h"
#include "taskLib.h"
#include "semLib.h"
#include "stdio.h"
/* function prototypes */
void taskOne(void);
void taskTwo(void);
/* globals */
#define ITER 10
SEM_ID semBinary;
int global = 0;
void binary(void)
{
int taskIdOne, taskIdTwo;
/* create semaphore with semaphore available and queue tasks on FIFO basis */
semBinary = semBCreate(SEM_Q_FIFO, SEM_FULL);
/* Note 1: lock the semaphore for scheduling purposes */
semTake(semBinary,WAIT_FOREVER);
/* spawn the two tasks */
taskIdOne = taskSpawn("t1",90,0x100,2000,(FUNCPTR)taskOne,0,0,0,0,0,0,0,0,0,0);
taskIdTwo = taskSpawn("t2",90,0x100,2000,(FUNCPTR)taskTwo,0,0,0,0,0,0,0,0,0,0);
}
void taskOne(void)
{
int i;
for (i=0; i < ITER; i++)
{
semTake(semBinary,WAIT_FOREVER); /* wait indefinitely for semaphore */
printf("I am taskOne and global = %d......................\n", ++global);
semGive(semBinary); /* give up semaphore */
}
}
void taskTwo(void)
{
int i;
semGive(semBinary); /* Note 2: give up semaphore(a scheduling fix) */
for (i=0; i < ITER; i++)
{
semTake(semBinary,WAIT_FOREVER); /* wait indefinitely for semaphore */
printf("I am taskTwo and global = %d----------------------\n", --global);
semGive(semBinary); /* give up semaphore */
}
}
2012年2月1日 星期三
轉貼 VxWorks thread同步(使用Semaphore)
訂閱:
張貼留言 (Atom)
winsock2.h redefined問題
解法: #define _WINSOCKAPI_ // stops windows.h including winsock.h #include #include
-
昨天要回新竹的路上,差點A到一臺摩托車, 可以清楚看到路口是綠燈,可是這位老兄,竟然從左方過來要待轉, 旁邊的女騎士也差點A到他,尖叫了一聲... 緊急煞車的同時,第一次感受到ABS做動,還好平安無事... 奉勸大家車子一定要裝行車記錄器阿~
-
呼,終於寫到最後一篇了,我竟然拖了半年才寫完… 呵,不過總算是有始有終啦!! 最後一天的早上,是自由活動的時間,我們跟著導遊前往市區觀光, 一般名牌族的,會跟著導遊去購買包包、配件, 而我跟小丸子沒啥錢,只能在市區附近拍拍照, 首先,我們搭捷運前往市區, ...
-
離開了超級天堂海灘,接著,我們來到了天堂海灘, 由這張入門的壁畫,就知道,這裡可是天體營的”天堂”呢!!! 當然囉,猥褻的動作,一定是不能少的!!! 覺得自己好像是一個色老頭阿…^^” 入口處呢,還有一間鴿舍(?),連鴿舍都可以弄得很好看~ ...
沒有留言:
張貼留言