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.
Fork of Task641 by
Revision 6:2e463846b575, committed 2016-03-14
- Comitter:
- noutram
- Date:
- Mon Mar 14 16:30:25 2016 +0000
- Parent:
- 5:31707531f715
- Child:
- 7:cd015e83995a
- Commit message:
- Comparing a yielding wait and a spinning-wait
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Mar 09 17:55:53 2016 +0000
+++ b/main.cpp Mon Mar 14 16:30:25 2016 +0000
@@ -23,67 +23,32 @@
//Thread ID for the Main function (CMSIS API)
osThreadId tidMain;
-//Thread sychronisation primatives
-Mutex lock1;
-Mutex lock2;
-unsigned long sw1Count = 0;
-unsigned long sw2Count = 0;
-
void thread1( const void* arg )
{
pc.printf("Entering thread 1\n");
while (true) {
yellowLED = 1;
-
- //Start critical section
- lock1.lock();
-
- sw1Count++;
- printf("\nCount1 = %lu", sw1Count);
-
- Thread::wait(1); //1ms
-
- //End critical section
- lock1.unlock();
-
- if (SW1 == 1) {
- lock2.lock();
- sw2Count--;
- lock2.unlock();
- }
-
+ Thread::wait(DELAY);
yellowLED = 0;
- Thread::wait(DELAY);
+ Thread::wait(DELAY);
}
}
+//This thread has higher priority
void thread2( const void* arg )
{
pc.printf("Entering thread 2\n");
while (true) {
redLED = 1;
-
- //Start critical section
- lock2.lock();
-
- sw2Count++;
- printf("\nCount2 = %lu", sw2Count);
-
- Thread::wait(1); //1ms
-
- //End critical section
- lock2.unlock();
-
- if (SW2 == 1) {
- lock1.lock();
- sw1Count--;
- lock1.unlock();
- }
-
+ if (SW1 == 1) {
+ //wait_ms(osWaitForever);
+ Thread::wait(osWaitForever);
+ } else {
+ Thread::wait(DELAY);
+ }
redLED = 0;
- Thread::wait(DELAY);
-
- }
+ Thread::wait(DELAY);
+ }
}
@@ -97,8 +62,9 @@
tidMain = Thread::gettid();
//Threads
- Thread t1(thread1);
- Thread t2(thread2);
+ Thread t1(thread1, NULL, osPriorityNormal);
+ //Thread t2(thread2, NULL, osPriorityNormal);
+ Thread t2(thread2, NULL, osPriorityAboveNormal);
pc.printf("Main Thread\n");
while (true) {