Maapi API throwing error while running in Multiple thread

Hi ,
I am trying to using the maapi API to perform the SET and GET operation using the MAAPI API,
when i performed/executed this operation in 1 thread it works fine , but when i try to execute this operation using multiple thread (lets say using 10 thread), i am getting error "User seesion already exists on sock"

Please let me know how to using MAAPI APIs in multiple threads
Pasted sample code and error log.


Below are the Error Log: -

 25-Apr-2017::11:26:15.001 25031/b7863b70/7 SEND {
 25-Apr-2017::11:26:15.001 25031/b6461b70/7 SEND op=100 isrel=0 th=-1 {#Bin<admin>,{{66,55,44,33},0},maapi,1,false,[#Bin<admin>],{undefined,undefined,undefined,#Bin<pldConfig_object.c:1(2)....>}}
op=100 isrel=0 th=-1 {#Bin<admin>,{{66,55,44,33},0},maapi,1,false,[#Bin<admin>],{undefined,undefined,undefined,#Bin<pldConfig_object.c:1(2)....>}}
INTERNAL ERROR: Unexpected data on  socket! 100 50

INTERNAL ERROR: Unexpected data on  socket! 100 1869488243

 25-Apr-2017::11:26:15.003 25031/b6461b70/7 SEND op=140 isrel=0 th=-1 {2,2,0,0,0,{
 25-Apr-2017::11:26:15.003 25031/b4affb70/7 SEND op=140 isrel=0 th=-1 undefined,undefined,undefined,#Bin<pldConfig_object.c:1(2)....>}}
DEBUG item already exists - User session already exists on sock

Sample Code :-

static long long * readCellConf(int *numgets)
    inet_aton("", &in);
    addr.sin_addr.s_addr = in.s_addr;
    addr.sin_family = AF_INET;
    addr.sin_port = htons(4565);

    if ((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0 )
        confd_fatal("Failed to open socket\n");

    if (maapi_connect(sock, (struct sockaddr*)&addr,
                sizeof (struct sockaddr_in)) < 0)
        confd_fatal("Failed to confd_connect() to confd \n"); = AF_INET;
    inet_aton("", &ip.ip.v4);

    **maapi_start_user_session(sock, user, context, groups, 1, &ip, CONFD_PROTO_TCP);**
**    tid = maapi_start_trans(sock, dbname, CONFD_READ_WRITE);**
**    maapi_set_namespace(sock, tid, samsung5g_access_acpf_call__ns);**

    maapi_create(sock, tid, "/managed-element/fg-nodeb-function/fg-cell/fg-cell-entries/{%d}", create_list);
    maapi_init_cursor(sock, tid, &mc, "/managed-element/fg-nodeb-function/fg-cell/fg-cell-entries/");

    if (maapi_set_elem2(sock, tid, "11", "/managed-element/fg-nodeb-function/fg-cell/fg-cell-entries/{%d}/cell-identity",set_elem)
            != CONFD_OK) {

    OK(maapi_get_u_int32_elem(sock, tid, &cellNum, "/managed-element/fg-nodeb-function/fg-cell/fg-cell-entries/{%x}/cell-num", &mc.keys[0]));

    *start_time = mstime();
    printf("start-time : readCellConf = %lld\n", *start_time);

    for (i=0; i< *numgets; i++)
        OK(maapi_get_u_int32_elem(sock, tid, &cellId, "/managed-element/fg-nodeb-function/fg-cell/fg-cell-entries/{%x}/cell-identity",&mc.keys[0]));

int main(int argc, char **argv)

<<<<<< Calling readCellConf() function by creating thread >>>>>>>>>>>>>

for (i = 0; i< 3;i++)
    gResPerSec = 0;
    trigger_time = 5+time(NULL);
    for(loop = 0; loop < mythread[i]; loop++)
        **s = pthread_create(&tread_id[loop],&attr, &readCellConf, &mygets[i]);**
    for(loop = 0; loop < mythread[i]; loop++)
        s = pthread_join(tread_id[loop],&res);

s = pthread_attr_destroy(&attr);
if (s != 0)
    printf("pthread_attr_destroy failed s = %d\n",s);

return CONFD_OK;

The issue here is that the application is mixing up its CDB and/or MAAPI sockets - e.g. two threads trying to use the same socket at the same time.
I.e. a CDB or MAAPI API function makes a request to ConfD, and get a response back from ConfD that doesn’t match the request.
The examples.confd/intro/9-c_threads/ example show how to handle sockets when using multiple threads.