Synchronization objects

Multi-threaded applications are impossible without a thread execution coordination. This is achieved with help of synchronization objects. Synchronization class has a set of methods, some of them may block execution of the calling thread, until some condition is met.

Most of synchronization objects in CCore can be named in constructor, using a TextLabel. If the name is not given explicitly, then some auto-generated name is used. In HCore the provided name is ignored, but in XCore it is used by the system log and an event recorder. You can get the name of a synchronization object in XCore by the method getName().

Blocking methods usually have four variants: try-variant which don't block, main variant without timeout, and timed variants with the MSec timeout and with the TimeScope timeout. The variant without timeout always successful (but may block indefinitely). Other variants return the bool return value, which indicates if the method was successful.

Releasing methods in XCore usually have three variants: common variant can be called only in a task context, "_int" variant can be called only in the interrupt context and "_any" variant can be called in any context.

Releasing methods often have associated methods, which return a Function object, bound with the call of the correspondent releasing method.


   // give
   
   void give();

   // functions
   
   Function<void (void)> function_give() { return FunctionOf(this,&Sem::give); }

If several threads are blocked on a synchronization object, then they are organized in a priority queue. When one thread should be released, the most prioritized thread is picked up. The thread priority counts first, the order of putting into the queue counts last. If the priority of the released task is higher, than the priority of the running task, task switch happens immediately.