Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Mutex in RTOSes in this specific situation

Status
Not open for further replies.

dizgah

Member level 5
Joined
Nov 8, 2009
Messages
91
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
iran-8par
Activity points
2,049
Hi every one,
Consider the following codes:
Code:
/*----------------------------------------------------------------------------
 First Thread 
 *---------------------------------------------------------------------------*/
void Thread1 (void const *argument) 
{
	for (;;) 
	{
		osMutexWait(mutex, osWaitForever); 
                Thread1_Functions;
		osMutexRelease(mutex);	
	}
}

/*----------------------------------------------------------------------------
  Second Thread  
 *---------------------------------------------------------------------------*/
void Thread2 (void const *argument) 
{
	for(;;)
	{
		osMutexWait(mutex, osWaitForever);
                Thread2_Functions;
		osMutexRelease(mutex);
	}
}

As far as I've noticed from RTOS's scheduling ,RTOS assign a specific time to each task and after this time is over,it switches to the other task.
Then in this specific time,inside task's infinite loop ,maybe loop is repeated several times until task's specific time finished.
Assume task is finished in less than of it's time's half,then it has a time to fully run this task once again :
in last line after releasing mutex , then it will achieve mutex before than task2 for second time,Am I true ?
assume timer tick occur when MCU run Thread1_Functions for second time,then task2 cant run because mutex owned by task1, RTOS run task 1 again and if timer tick occur every time in the Thread1_Functions, then task2 has no chance to running,Am I true ?
 

.....
As far as I've noticed from RTOS's scheduling ,RTOS assign a specific time to each task and after this time is over,it switches to the other task.
Then in this specific time,inside task's infinite loop ,maybe loop is repeated several times until task's specific time finished.....

when RTOS assign a task in RUNNING state , it starts executing it (provided no wait or blocked state is occuring). it completes this task in chunks of task time , until it is finished.

but , it is not like , "the task is repeated several times until its allotted time is over."
 

thank for reply,
assume timer tick = 50ms and task_1 need 5ms to execute one time,i mean
Code:
void Thread2 (void const *argument) 
{
	for(;;)
	{
//assume t=0ms here in the starting point of task
		osMutexWait(mutex, osWaitForever);
                Thread2_Functions;
		osMutexRelease(mutex);
//t=5ms here in the end of the instructions
	}
}
we setts timer tick 50ms because of other tasks and ... needs
can you explain for this situation?
WBR.
 

I am using KEIL RTX RTOS which used pre-emptive round robin scheduler.I have a LCD for displaying data and a few tasks have access to this LCD(there are some other tasks also),These tasks need fixed time for handling the LCD(e.g. first task handle LCD for displaying it's data for 50 seconds and after 50 seconds,second task handle and displays it's data for 10 seconds). I know i must use mutex for managing accessing to LCD.but i dont know how i must manage its for fixed times?LCD tasks are in the lowest priority and if there are not any other task to execution these tasks will be execute for displaying messages.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top