+/** \name Functions
+ * \ingroup XBT_context
+ */
+/* @{ */
+/** Context module initialization
+ *
+ * \warning It has to be called before using any other function of this module.
+ */
+void xbt_context_init(void)
+{
+ if(!current_context) {
+ current_context = init_context = xbt_new0(s_xbt_context_t,1);
+ init_context->exception = xbt_new(ex_ctx_t,1);
+ XBT_CTX_INITIALIZE(init_context->exception);
+ __xbt_ex_ctx = __context_ex_ctx;
+ __xbt_ex_terminate = __context_ex_terminate;
+ context_to_destroy = xbt_swag_new(xbt_swag_offset(*current_context,hookup));
+ context_living = xbt_swag_new(xbt_swag_offset(*current_context,hookup));
+ xbt_swag_insert(init_context, context_living);
+ }
+}
+
+/** Garbage collection
+ *
+ * Should be called some time to time to free the memory allocated for contexts
+ * that have finished executing their main functions.
+ */
+void xbt_context_empty_trash(void)
+{
+ xbt_context_t context=NULL;
+
+ while((context=xbt_swag_extract(context_to_destroy)))
+ xbt_context_destroy(context);
+}
+
+/**
+ * \param context the context to start
+ *
+ * Calling this function prepares \a context to be run. It will
+ however run effectively only when calling #xbt_context_schedule
+ */
+void xbt_context_start(xbt_context_t context)
+{
+#ifdef USE_PTHREADS
+ /* Launch the thread */
+ DEBUG0("**** Locking ****");
+ pthread_mutex_lock(&(context->mutex));
+ DEBUG0("**** Pthread create ****");
+ xbt_assert0(!pthread_create(context->thread, NULL, __context_wrapper, context),
+ "Unable to create a thread.");
+ DEBUG0("**** Going to jail ****");
+ pthread_cond_wait(&(context->cond), &(context->mutex));
+ DEBUG0("**** Unlocking ****");
+ pthread_mutex_unlock(&(context->mutex));
+#else