find the issue: #include "mbed.h"
#include <exception>

DigitalOut ledYellow(D2);
DigitalOut ledAmber(D3);
DigitalOut ledRed(D4);

Thread thread2;
Thread thread3;

int counter = 0;

// Subroutine for any LEDs
void ledAny (DigitalOut *ledA){
    while(true){
        *ledA = 1;
        ThisThread::sleep_for(500ms);
        *ledA =0;
        ThisThread::sleep_for(1500ms);
        printf("My pointer is %p\n", *ledA);
    }
}


// main() runs in its own thread in the OS
int main(){

    thread2.start(callback(ledAny, &ledYellow));
    ThisThread::sleep_for(1000ms);
    thread3.start(callback(ledAny, &ledAmber));

    while (true) {
        counter = counter + 1;

        ledRed.write(true);
        ThisThread::sleep_for(500ms);
        ledRed.write(false);
        ThisThread::sleep_for(500ms);

        if (counter>20){
            thread2.terminate();
        }


    }
}