Java has a convenient feature where you can declare a function as a synchronized function. Then, all threads that attempt to call it will be blocked so that only one thread is running that function at a time - thus protecting the data manipulation that occurs within the function from becoming corrupted by too many cooks in the kitchen.
Anyway, I like it. It is way better (more convenient) than the C synchronization mechanism (at least in Windows I dont know about Linux & Mac) and it gets the job done.
But, I want to extend it a little. You see there is that case where you have 7 or 8 functions for managing a particular data member of a class, and you want them to all be serialized together (block all threads but one across several functions at once).
Why not allow the synchronize keyword to use array notation, to group the functions, like so
Class MyObj
Synchronize[1] Function Incr_Var1()
Synchronize[1] Function Decr_Var1()
Synchronize[2] Function Incr_Var2()
Synchronize[2] Function Decr_Var2()
End Class
In this way, all the functions with the same Synchronize subscript would be mutually Synchronized. The subscripts would not need to be defined. They could probably be named instead of numbered - the compiler will sort it out, so they just have to be unique tokens. In fact, you could even use a member variable name as a unique token - that tells other developers what resource it is you are protecting
The tokens would be scoped at the object level, meaning you could use the same tokens in other objects without worrying about overlap and cross object synchronization.
Maybe we could extend it further with a keyword for declaring a global synchronization that crosses object boundaries.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Java has a convenient feature where you can declare a function as a synchronized function. Then, all threads that attempt to call it will be blocked so that only one thread is running that function at a time - thus protecting the data manipulation that occurs within the function from becoming corrupted by too many cooks in the kitchen.
Anyway, I like it. It is way better (more convenient) than the C synchronization mechanism (at least in Windows I dont know about Linux & Mac) and it gets the job done.
But, I want to extend it a little. You see there is that case where you have 7 or 8 functions for managing a particular data member of a class, and you want them to all be serialized together (block all threads but one across several functions at once).
Why not allow the synchronize keyword to use array notation, to group the functions, like so
Class MyObj
Synchronize[1] Function Incr_Var1()
Synchronize[1] Function Decr_Var1()
Synchronize[2] Function Incr_Var2()
Synchronize[2] Function Decr_Var2()
End Class
In this way, all the functions with the same Synchronize subscript would be mutually Synchronized. The subscripts would not need to be defined. They could probably be named instead of numbered - the compiler will sort it out, so they just have to be unique tokens. In fact, you could even use a member variable name as a unique token - that tells other developers what resource it is you are protecting
The tokens would be scoped at the object level, meaning you could use the same tokens in other objects without worrying about overlap and cross object synchronization.
Maybe we could extend it further with a keyword for declaring a global synchronization that crosses object boundaries.