Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lesson 10 homework #115

Open
wants to merge 5 commits into
base: Vadym.Mishchuk
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions kthread_example/kthread_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@
#include <linux/timer.h>
#include <linux/delay.h>
#include <linux/spinlock.h>
#include <linux/rtmutex.h>

#define N_THR 4

static struct task_struct *threads[N_THR];

DEFINE_SPINLOCK(critical_section);
DEFINE_RT_MUTEX(critical_section);

static int thread_fn(void *ptr)
{

while (!kthread_should_stop()) {
pr_info("Kthread example: in thread %d\n", (int)ptr);
spin_lock(&critical_section);
msleep_interruptible(200);
spin_unlock(&critical_section);
rt_mutex_lock(&critical_section);
msleep_interruptible(200);
rt_mutex_unlock(&critical_section);
msleep_interruptible(800);
}

Expand All @@ -35,8 +36,8 @@ int thread_init(void)
pr_info("Kthread example: in init\n");

for (i = 0; i < N_THR; i++)
threads[i] = kthread_run(thread_fn,
(void *)i, thread_format, i);
threads[i] = kthread_run(thread_fn,
(void *)i, thread_format, i);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Insignificant changes


return 0;
}
Expand Down