Synchronising multiple threads

Technical questions regarding the xTIMEcomposer, xSOFTip Explorer and Programming with XMOS.
leobodnar
Junior Member
Posts: 5
Joined: Mon May 07, 2018 9:26 am

Synchronising multiple threads

Postby leobodnar » Thu Oct 15, 2020 10:58 am

What are the ways of having multiple threads synchronised?
Say 7 threads are waiting and get released by the 8th at once?
Wiring 8 single ports together will work but is silly.

Essentially - can several threads wait on a shared resource?

Leo
User avatar
CousinItt
XCore Addict
Posts: 179
Joined: Wed May 31, 2017 6:55 pm

Postby CousinItt » Thu Oct 15, 2020 10:38 pm

Can you be a bit more specific about where these threads reside? Are they running on the same core, the same tile, or anywhere in a network of devices?
leobodnar
Junior Member
Posts: 5
Joined: Mon May 07, 2018 9:26 am

Postby leobodnar » Thu Oct 15, 2020 11:44 pm

CousinItt wrote:
Thu Oct 15, 2020 10:38 pm
Can you be a bit more specific about where these threads reside? Are they running on the same core, the same tile, or anywhere in a network of devices?
Each thread/task is running on its own logic core on the same tile.
Perhaps, using timer event is viable (assuming all timers on the same tile report the same time.)
Leo
User avatar
CousinItt
XCore Addict
Posts: 179
Joined: Wed May 31, 2017 6:55 pm

Postby CousinItt » Sun Oct 25, 2020 7:05 pm

If the tasks are on the same tile then they share memory. An unsafe pointer can be distributed to the dependent tasks, and they can each wait for the value to change. Would that work for you?

<EDIT/> See also this thread: viewtopic.php?t=3061.
leobodnar
Junior Member
Posts: 5
Joined: Mon May 07, 2018 9:26 am

Postby leobodnar » Tue Oct 27, 2020 12:41 pm

Thanks,
Yes, I have ended up using a shared flag in .data section - initially set to zero with all slave tasks waiting for it to be set and the master task the only one writing [1] to it when it's done.
Then I am using locks to sync the hardware resources use, but that's another story.
It all looked very bamboozling until I wrote it in assembly and it's suddenly clean and simple.
Cheers
Leo
User avatar
aclassifier
Respected Member
Posts: 366
Joined: Wed Apr 25, 2012 8:52 pm

Postby aclassifier » Tue Oct 27, 2020 8:59 pm

I wrote a barrier task (I think that's a term for this pattern) for synchronizing my PWM LEDs, to be covered in a blog note [1]. I tested with interface and channels, and also with combinable or not, and was able to get some/one of those running stable. I could publish some of the basic code here later this week. But I will also update the note with the full code. I promise to be back.

[1] My XC softblinking PWM notes Disclaimer no ads, money, gifts, just fun and expenses with my blog notes. This does not contain presently contain the barrier code, I will place it there during this week.
--
Øyvind Teig
Trondheim (Norway)
https://www.teigfam.net/oyvind/home/

Who is online

Users browsing this forum: No registered users and 4 guests