#include "server/gdb_server.h"
 
 
-static int64_t current_threadid = -1;
 
 static void hex_to_str( char* dst, char * hex_src );
 static int str_to_hex( char* hex_dst, char* src );
 {
        int x;
        char *cp;
-
        if (! goi->isconfigure) {
                if (goi->argc != 0) {
                        if (goi->argc != 0) {
        /* Create it */
        target->rtos = calloc(1,sizeof(struct rtos));
        target->rtos->type = rtos_types[x];
+       target->rtos->current_threadid = -1;
        target->rtos->current_thread = 0;
        target->rtos->symbols = NULL;
        target->rtos->target = target;
        else if ( packet[0] == 'H') // Set current thread ( 'c' for step and continue, 'g' for all other operations )
        {
                if ((packet[1] == 'g') && (target->rtos != NULL))
-                       sscanf(packet, "Hg%16" SCNx64, ¤t_threadid);
+                       sscanf(packet, "Hg%16" SCNx64, &target->rtos->current_threadid);
                gdb_put_packet(connection, "OK", 2);
                return ERROR_OK;
        }
 int rtos_get_gdb_reg_list(struct connection *connection)
 {
        struct target *target = get_target_from_connection(connection);
-
+       int64_t current_threadid = target->rtos->current_threadid;
        if ( ( target->rtos != NULL ) &&
                 ( current_threadid != -1 ) &&
                 ( current_threadid != 0 ) &&
 
 
        symbol_table_elem_t * symbols;
        struct target *target;
-
+       /*  add a context variable instead of global variable */
+       int64_t current_threadid;
        threadid_t current_thread;
        struct thread_detail* thread_details;
        int thread_count;