Basic fundamental of RTOS

WBahn

Joined Mar 31, 2012
29,979
I don't think there is any difference between the task, process and thread. They all are same thing.

I am trying to understand the meaning of following definition for interprocess communication.

"Inter process communication is a process of real time operating system that allow one process to communicate with the another process."

I don't understand how one task/process communicate with the another task/process. I only understand task/process can share the resources like CPU time Or memory.
Imagine you and someone else are both creating something out of wood -- maybe you are making a lamp and the other person is making a baseball bat. You both need to use a lathe, but there's only one. That lathe is a resource. The lathe is located inside a room, along with a white board for you to sketch your design and do some calculations on how big to make things. Every hour, on the hour, you get to go in an use the lathe and whiteboard, but only for half an hour. Then you must leave, so you take your partially completed work off the lathe and erase your stuff from the whiteboard and clean up the room and depart. The other person comes in every hour on the half-hour and is under the same rules. As far as each of you is concerned, you are the only one using the room. That's resource sharing.

Now imagine that you are both working on the same project -- maybe you are making the top of the lamp and they are making the bottom of the lamp. You need to know exactly how large the diameter of the bottom of your piece needs to be so that it will match with the top of their piece. But the other person is responsible for determining that diameter (perhaps they have the metal ring that will fit around the joint). So, at some point while they have the room, they write the needed diameter on the white board but they don't erase it when they leave. Now when you come in, it is still there for you to see. That's interprocess communication.
 

Thread Starter

Kittu20

Joined Oct 12, 2022
463
Imagine you and someone else are both creating something out of wood -- maybe you are making a lamp and the other person is making a baseball bat. You both need to use a lathe, but there's only one. That lathe is a resource. The lathe is located inside a room, along with a white board for you to sketch your design and do some calculations on how big to make things. Every hour, on the hour, you get to go in an use the lathe and whiteboard, but only for half an hour. Then you must leave, so you take your partially completed work off the lathe and erase your stuff from the whiteboard and clean up the room and depart. The other person comes in every hour on the half-hour and is under the same rules. As far as each of you is concerned, you are the only one using the room. That's resource sharing.

Now imagine that you are both working on the same project -- maybe you are making the top of the lamp and they are making the bottom of the lamp. You need to know exactly how large the diameter of the bottom of your piece needs to be so that it will match with the top of their piece. But the other person is responsible for determining that diameter (perhaps they have the metal ring that will fit around the joint). So, at some point while they have the room, they write the needed diameter on the white board but they don't erase it when they leave. Now when you come in, it is still there for you to see. That's interprocess communication.
Is there any inter process communication in the example ?

Print numbers in sequence using multiple threads

Example:

Input: No of threads(n): 3, Print numbers upto(N): 10

Output:

Code:
T1-1 T2-2 T3-3 T1-4 T2-5 T3-6 T1-7 T2-8 T3-9 T1-10
 

djsfantasi

Joined Apr 11, 2010
9,156
I don't think there is any difference between the task, process and thread. They all are same thing.

I am trying to understand the meaning of following definition for interprocess communication.

"Inter process communication is a process of real time operating system that allow one process to communicate with the another process."

I don't understand how one task/process communicate with the another task/process. I only understand task/process can share the resources like CPU time Or memory.
There are different methods of inter-process communication. Here is a couple of examples

A region of memory is reserved to be shared between one or more processes. One process changes a value which can then be read by another process. The code to share memory must be written to ensure data integrity.

Another technique uses methods (programmed functions) to send and receive a message (variable length data) between two or more processes.
 

Thread Starter

Kittu20

Joined Oct 12, 2022
463
A region of memory is reserved to be shared between one or more processes. One process changes a value which can then be read by another process. The code to share memory must be written to ensure data integrity.
Is the example I have given in this Post #22 an example of inter process communication?

I think because each task should know what value is set by its previous task then only it can print next value
 

BobTPH

Joined Jun 5, 2013
8,813
That would be a silly usage of threads. I don't think it helps your understanding to come io with examples in which there is no benefit to using threads and the threaded solution is more complicated than straight coding.
 

Thread Starter

Kittu20

Joined Oct 12, 2022
463
That would be a silly usage of threads. I don't think it helps your understanding to come io with examples in which there is no benefit to using threads and the threaded solution is more complicated than straight coding.
Do you have any specific example in mind apart from the ones given by @djsfantasi ?
 

djsfantasi

Joined Apr 11, 2010
9,156
Do you have any specific example in mind apart from the ones given by @djsfantasi ?
Processing a normal form of search specifications by performing parallel AND and OR operations on lists. IPCF is used to communicate the status and results of each parallel operation / task to the next highest logical operator task. Used in searching data stored in a database.
 

Thread Starter

Kittu20

Joined Oct 12, 2022
463
Multiple tasks share a resource, which is called a shared resource.

I am presenting some examples that share resources.

  1. Multiple tasks can share a CPU time.
  2. Multiple tasks can share the same memory.
  3. Multiple tasks can share the same peripheral ( UART )

I want to understand what is the time critical resource.

When one task is accessing a resource, another task cannot access the same resource until the first task releases the resource.

Are these all (CPU time, Memory and UART) time critical resources?
 

WBahn

Joined Mar 31, 2012
29,979
Time critical resources refers to ANY resource for which getting access to it is time critical. What is time critical depends entirely on the problem being solved.
 

Thread Starter

Kittu20

Joined Oct 12, 2022
463
What is time critical depends entirely on the problem being solved.
Task 1 is transferring data to the device over UART.

Task 2 is receiving data from device over UART

Is this condition time critical condition because both task sharing same UART?
 

WBahn

Joined Mar 31, 2012
29,979
Task 1 is transferring data to the device over UART.

Task 2 is receiving data from device over UART

Is this condition time critical condition because both task sharing same UART?
There is no way to tell whether it is time critical or not, it depends on the problem and also the UART's capabilities. If you are bit-banging the UART, then you have timing requirements that have to be met pretty tightly. If the UART is self-contained and has a reasonably sized input and output buffer, then it is not nearly as time critical that it be serviced promptly.
 

WBahn

Joined Mar 31, 2012
29,979
Now I understand what is the critical time resource. Mutex is used to protect the resource but could not figure out the real problem.
Huh?

Mutex's have nothing to do with time criticality. Mutex's (i.e., MUTual EXclusion objects) are used to ensure that only one thread has access to a resource at any given time. Time criticality has to do with being sure that tasks that need to do things at specific times (or respond within a certain time limit) are able to do so. Very different thing.
 

Thread Starter

Kittu20

Joined Oct 12, 2022
463
Mutex's have nothing to do with time criticality. Mutex's (i.e., MUTual EXclusion objects) are used to ensure that only one thread has access to a resource at any given time.
Task 1 is transferring data to the device over UART.

Task 2 is receiving data from device over UART

Is it necessary to use mutex in this example if yes then why and if not then why not?
 

djsfantasi

Joined Apr 11, 2010
9,156
Task 1 is transferring data to the device over UART.

Task 2 is receiving data from device over UART

Is it necessary to use mutex in this example if yes then why and if not then why not?
There is a third possibility. Maybe. One cannot answer either of your questions without further information.

As WBahn has mentioned, to answer you, one needs to know if it is a hardware UART or software (bIt-banging) UART. What speeds do communications occur at and are there send/receive buffers in hardware and if so what are there sizes?

So, maybe…
 

Thread Starter

Kittu20

Joined Oct 12, 2022
463
There is a third possibility. Maybe. One cannot answer either of your questions without further information.

As WBahn has mentioned, to answer you, one needs to know if it is a hardware UART or software (bIt-banging) UART. What speeds do communications occur at and are there send/receive buffers in hardware and if so what are there sizes?

So, maybe…
It's hardware UART, baud rate 9600, data bits 8bits
 

Thread Starter

Kittu20

Joined Oct 12, 2022
463
And the size of its internal buffers?

At that speed and a nominal buffer size, I wouldn’t think an RTOS nor a mutex would be necessary.
I agree with your statement. I needed a real situation to understand mutex which I created and present to you.

So in the example I presented, for how much speed and buffer size, can RTOS or mutex be needed.
 
Top