Critical Section in Synchronization

34 views
Skip to first unread message

max juk

unread,
Nov 14, 2022, 5:55:12 AM11/14/22
to The Ring Programming Language
Hallo ring Team,

does the ring language support the Critical Section in Synchronization?

like Synchronized in Python and java
or semaphore in c and c++

Ilir

unread,
Nov 14, 2022, 6:33:39 AM11/14/22
to The Ring Programming Language
Hello Max,

I believe you are referring to threads while asking about Critical Section? Ring creates another VM instances while running threads, therefore it is possible to run threads without synchronization. You need only to follow following rule about the global variables:

Ring uses jagged arrays (lists) to take advantage: where each thread can use its own sub-list to work on data independently. Once thread finishes processing of the data, parent lists can be swapped to exchange sub-lists between the parent and the thread for new processing.

This however works without synchronization only with one thread. More threads will require synchronization, unless parent is the one doing swap which requires signaling.

Other kind (not jagged) of the global variables requires synchronization. You have more than one library available (ringlibuv, ringthread, allegro) depending on your requirements, my preferred is ringlibuv because of the nice synchronization implementation where only one thread is allowed to write and multiple threads can read

Ilir

unread,
Nov 14, 2022, 8:15:27 AM11/14/22
to The Ring Programming Language
Hello All,

@Mahmoud, it would be nice to have QReadWriteLock supported for Qt apps in Ring because it looks simpler than LibUV barrier.

Mahmoud Fayed

unread,
Nov 14, 2022, 8:21:46 AM11/14/22
to The Ring Programming Language
Hello Ilir

>> "@Mahmoud, it would be nice to have QReadWriteLock supported for Qt apps in Ring because it looks simpler than LibUV barrier."

Thanks for pointing to this class
In the future, once I add more classes to RingQt, It will be on my list too

Greetings,
Mahmoud

Ilir

unread,
Nov 14, 2022, 1:01:55 PM11/14/22
to The Ring Programming Language
Hello Mahmoud,

Thanks for pointing to this class

You're Welcome. Hopefully it comes with Ring 1.18 since the libraries will be rebuilt.

Greetings,
Ilir
Reply all
Reply to author
Forward
0 new messages