Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6125447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:14:54+00:00 2026-05-23T16:14:54+00:00

I have an assignment to build support for distributed mutual exclusion using raymond’s algorithm

  • 0

I have an assignment to build support for distributed mutual exclusion using raymond’s algorithm in freebsd.

This requires a kernel thread to always listen on a udp port for messages from other systems and act accordingly.

I’m creating a thread using thread_create, but inside every call to socreate creates a kernel panic.
What’s the best way to do what I’m doing? I couldn’t find any good tutorials on kernel networking in freebsd.

On another note, maybe the mainproc variable is not set correctly. How can I find out current struct proc* or struct thread*?

My current code is like this:

static struct proc *mainproc;
static int val;
static int main_thread_finish;

static struct socket *listenso;
static struct sockaddr_in listenadr;

static void main_thread(void* data)
{
    static int res;
    printf("In thread\n");
    res = socreate(AF_INET, &listenso, SOCK_DGRAM, IPPROTO_UDP, mainproc->p_ucred, mainproc->p_singlethread);
    printf("socreate res: %d\n", res);

    listenadr.sin_family = AF_INET;
    listenadr.sin_port = htons(1234);
    listenadr.sin_addr.s_addr = 0;
    res = sobind(listenso, (struct sockaddr*)&listenadr, mainproc->p_singlethread);
    printf("bind res: %d\n", res);

    while(!main_thread_finish)
    {
            pause("DUMMY", hz);
    }
    printf("kthread exiting...\n");
   kthread_exit();
}

static int
raymond_module_load(struct module *module, int cmd, void *arg)
{
    int error = 0;

    switch (cmd) {
    case MOD_LOAD :
            val = 12345;
            main_thread_finish = 0;
            kproc_create(main_thread, NULL, &mainproc, 0, 0, "raymond_main_thread");
            printf("Module loaded - kthread created\n");
            break;
    case MOD_UNLOAD :
            main_thread_finish = 1;
            printf("Waiting for thread to exit...\n");
            pause("TWAIT", 3*hz);
            printf("Module unload...\n");
            break;
    default :
            error = EOPNOTSUPP;
            break;
    }
    return (error);
}

static moduledata_t raymond_module_data = {
    .name = "raymond_module",
    .evhand = raymond_module_load,
    .priv = NULL };

DECLARE_MODULE(raymond_module, raymond_module_data, SI_SUB_KLD, SI_ORDER_ANY);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:14:54+00:00Added an answer on May 23, 2026 at 4:14 pm

    The call to socreate panics because mainproc->p_singlethread is NULL. This variable is not the thread associated with the process but is used to enforce “single-threading” within a process (see the function thread_single() in sys/kern/kern_thread.c for more details).

    Probably what you wanted to do was was to use curthread

    res = socreate(AF_INET, &listenso, SOCK_DGRAM, IPPROTO_UDP,
                curthread->td_ucred, curthread);
    ...
    res = sobind(listenso, (struct sockaddr*)&listenadr, curthread);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this assignment due that requires the usage of FLTK. The code is
I have an assignment in a language-independent class, and part of it is using
I have an assignment to create a GUI using MATLAB GUIDE and am having
I'm a beginner in Java and I have an assignment to build P2p File
Note: This is for a SWING course I am taking. I have an assignment
I'm doing a homework assignment in C. I have to build a calculator that
Is it possible to have assignment in a condition? For ex. if (a=some_func()): #
I have an assignment about fftw and I was trying to write a small
So I am being taught assembly and we have an assignment which is to
Are there exceptions for types which can't have thier assignment operator overloaded? Specifically, I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.