Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- umutaradag
- Date:
- 2011-08-04
- Revision:
- 2:ac3746d21033
- Parent:
- 1:5c7d8d760ece
File content as of revision 2:ac3746d21033:
#include "mbed.h" #include "semaphore.h" Ticker ticker; semaphore sharedVariableSem; volatile int sharedVariable; #define SEM_ENABLE 1 void incrementer() { #if SEM_ENABLE==1 if(semPend(&sharedVariableSem, 5) == SEM_ERR) return; #endif sharedVariable++; #if SEM_ENABLE==1 semPost(&sharedVariableSem); #endif } int main() { sharedVariable = 0; semInit(&sharedVariableSem, 1); ticker.attach(&incrementer, 0.25); while(1) { #if SEM_ENABLE==1 semPend(&sharedVariableSem, 10000); #endif printf("\nfirst val = %d\n",sharedVariable); sharedVariable++; wait(1); printf("second val = %d\n",sharedVariable); #if SEM_ENABLE==1 semPost(&sharedVariableSem); #endif wait(1); } }