How to sync tasks using FreeRTOS library? - freertos

I have 5 tasks(function) in 5 different which are running simultaneously. I want to implement like any function start running then other function should not run until the function completes its process.
I want to implement using FreeRTOS.
Example.
foo1.c
->Task1
foo2.c
->Task2
foo3.c
->Task3
foo4.c
->Task4
foo5.c
->Task5

It sounds like you need a mutex. Each task acquires the mutex when they start running, and release it when they are done. When any of the tasks is running, others are blocked on the mutex.

You need to use a mutex (mutually exclusive) semaphore.
Here is an example protecting the Serial Port of an ATmega Arduino Clone. This ensures that messages presented to the serial port by multiple tasks are not interleaved (corrupted).
You can see that the semaphore is taken before attempting to write to the serial port, and then given (freed) when the task has completed its activities.

Related

In iOS, if all the task can only be executed asynchronously on a serial queue, isn't it essentially becomes a concurrent queue?

according to apple's doc, tasks are still started in the order in which they were added to a concurrent queue, so it seems to me that there is no difference between a concurrent queue vs a serial queue where all its task are run by async.
correct me if I miss something
read bunch of documents and did not find the answer
The difference is how many tasks may run at the same time:
A serial queue only processes (runs) one task at time, one after another. A concurrent queue may process multiple tasks (on multiple thread) at the same time.
You typically use a serial queue to ensure only one task is accessing a resource at the same time. These are scenarios where you would traditionally use mutexes.
If you have tasks that would benefit from (and are able to) running concurrently at the same time, or tasks that are completely independent and thus don't care, you usually use a concurrent queue.

Communicate progress of work inside a Dask delayed task back to Client thread

I would like to use a Dask delayed task to call an external program, which outputs it's progress to STDOUT. In the delayed, I plan to monitor the STDOUT and would like to update the Client process that is waiting for the delayed task with progress information extracted from the STDOUT. Is there a recommended way for a delayed task to communicate with its Client processes, or do I need to roll my own?
You could achieve this kind of flow with any of the coordination primitives or actors provided by dask. From your description, the Queue or pubsub mechanisms seem like they might be favourite. You should note that all of these are generally means for low-frequency and low-volume communications.

Execute task after several async connections

I have several concurrent asynchronous network operations, and want to be notified after all of them finished receiving the data.
The current thread shall not be blocked, synchronous connections aren't an option, and all operations shall be executed concurrently.
How can I achieve that? Or is it more performant to execute all network operations successively, particularly looking at mobile devices?

How nexttuple and excute be called in storm framework

I think each task will contain an instance of spout or bolt, and a while or for block calls them, is it right?
If so, since every task coordinates to one of some threads running in a worker process, and there is probability that two or more tasks of the same spout or bolt are assigned to the same worker, in this case, do we need to sync (especially if the spout or bolt contains critical resources such as static members)? Why?
Yes, several tasks of the same spout/bolt could be assigned to the same worker and run in the same JVM. I recommend not to use static members that are not thread-safe - in this case you won't to need care about synchronization.

How to queue rails calls so function isn't run in parallel

I have some rails code that calls model1.func1(). A controller action calls this, where multiple people can be hitting it, as does a scheduled rake task. I want to make sure that model1.func1() cannot be called in parallel. If another thread needs to call at the same time, it should wait for model1.func() to finish. I guess I want to queue these calls. I was going to use sidekiq for this, but with only one worker. I read on a forum that
Sidekiq is not appropriate for the serial job and I don't want to make
it appropriate. Different tools are useful for different reasons,
jack of all trades master of none, etc.
What do you guys recommend instead?
I would consider beanstalkd with one worker process.

Resources