Priority Ceiling Example
#include <pthread.h>
pid_t child_pid;
struct sched_param old_param;
struct pthread_mutex_t mutex;
void raise_child_priority()
{
struct sched_param current;
sched_getparam(0, ¤t);
sched_getparam(child_pid, &old_param);
if(current.sched_priority > old_param.sched_priority) {
sched_setparam(child_pid, ¤t);
}
}
void lower_child_priority()
{
sched_setparam(child_pid, &old_param);
}
int access_shared_resource()
{
if(pthread_mutex_trylock(&mutex) < 0) {
if(errno == EBUSY) {
raise_child_priority();
if(pthread_mutex_lock(&mutex) < 0) return -1;
}
else {
return -1;
}
}
lower_child_priority();
/* Do stuff with the locked resource */
if(pthread_mutex_unlock(&lock) < 0) return -1;
return 0;
}
Recent Stories
Top DiscoverSDK Experts
Mendy Bennett
Experienced with Ad network & Ad servers.
Mobile | Ad Networks and 1 more
View Profile
Karen Fitzgerald
7 years in Cross-Platform development.
Mobile | Cross Platform Frameworks
View Profile
X
Compare Products
Select up to three two products to compare by clicking on the compare icon () of each product.
{{compareToolModel.Error}}Now comparing:
{{product.ProductName | createSubstring:25}} X
{{CommentsModel.TotalCount}} Comments
Your Comment