Initialize the task descriptor and spawn a task (thread).
unsigned int sample_start_connected_task( /*IN*/ sample_task_t * descr,
/*IN*/ sample_task_proc_t task,
/*IN*/ const char * db_name,
/*IN*/ void * param )
descr
The task descriptor to initialize:
typedef struct tag_sample_task
{
void * param;
unsigned int id;
volatile int stopped;
const char * db_name;
mco_db_h db_connection;
sample_task_proc_t proc;
mco_thread_t * t;
} sample_task_t;
task
db_name
param
descr.This function initializes the task descriptor by setting the thread procedure
proc, the db_name and param elements, then calls
mco_create_thread() to spawn the thread.
unsigned int
#include <common.h> #include <transdb.h> const char * db_name = "transdb"; #define N_THREADS 2 static sample_task_t tasks[N_THREADS]; ... void task1( sample_task_t * descriptor ) { MCO_RET rc; uint4 i; for (i = 0; i < n_iterations; i++) { mco_trans_h t; A a; char tag[64]; rc = mco_trans_start(descriptor->db_connection, MCO_READ_WRITE, MCO_TRANS_FOREGROUND, &t); if ( MCO_S_OK == rc ) { sprintf(tag, "Stream 1, rec %u\n", i); mem_write(tag); rc = A_new(t, &a); rc = A_ui4_put(&a, i); rc = A_tag_put(&a, tag, strlen(tag)); sample_sleep(nap_duration1); rc = mco_trans_commit(t); } } } int main(int argc, char* argv[]) { MCO_RET rc; mco_db_h db; sample_memory_t dbmem; mco_runtime_start(); rc = sample_open_database( db_name, transdb_get_dictionary(), DATABASE_SIZE, CACHE_SIZE, MEMORY_PAGE_SIZE, PSTORAGE_PAGE_SIZE, 1 + N_THREADS, &dbmem ); if ( MCO_S_OK == rc ) { rc = mco_db_connect(db_name, &db); if ( MCO_S_OK == rc ) { sample_start_connected_task(&tasks[0], task1, db_name, 0); ... } } ... }