Jump to content
Sign in to follow this  
leimli

How to achieve concurrency through SC_THREAD

Recommended Posts

Hi, everyone,

 

I am a starter of SystemC. I wrote a simple example with using SC_THREAD following the example in systemc source.

 

I have two classes which boot two threads, bootMAC and respondDrv. However, when I simulate this program, I observed that only bootMAC is running, respondDrv did not print anything. 
 
Are there anything I still need to add?
 

Thanks so much for you guys' help.

 

The code is follows.

 

class SYSCMAC : public sc_core::sc_module
{
public:
SC_HAS_PROCESS(SYSCMAC);
SYSCMAC(sc_module_name name) : sc_core::sc_module(name)
{
SC_THREAD(bootMAC);
}
 
void bootMAC()
{
while(true)
printf("in bootMAC\n");
}
};
 
class SYSCNETDEV : public sc_module
{
public:
   SC_HAS_PROCESS(SYSCNETDEV);
   SYSCNETDEV(sc_module_name name) : sc_core::sc_module(name)
   {
    SC_THREAD(respondDrv);
   }
 
   void respondDrv()
   {
    while(true)
    printf("in respondDrv\n");
   }
};
 
 
int sc_main(int argc, char **argv)
{
printf("hello world\n");
 
SYSCMAC *q = new SYSCMAC("mac");
SYSCNETDEV *sn = new SYSCNETDEV("qemu");
 
    sc_start();
 
    printf("start simulation now\n");
return 0;
}
 
 
 
 

Share this post


Link to post
Share on other sites

 

Hi, everyone,

 

I am a starter of SystemC. I wrote a simple example with using SC_THREAD following the example in systemc source.

 

I have two classes which boot two threads, bootMAC and respondDrv. However, when I simulate this program, I observed that only bootMAC is running, respondDrv did not print anything. 
 
Are there anything I still need to add?
 

Thanks so much for you guys' help.

 

The code is follows.

 

class SYSCMAC : public sc_core::sc_module
{
public:
SC_HAS_PROCESS(SYSCMAC);
SYSCMAC(sc_module_name name) : sc_core::sc_module(name)
{
SC_THREAD(bootMAC);
}
 
void bootMAC()
{
while(true)
printf("in bootMAC\n");
}
};
 
class SYSCNETDEV : public sc_module
{
public:
   SC_HAS_PROCESS(SYSCNETDEV);
   SYSCNETDEV(sc_module_name name) : sc_core::sc_module(name)
   {
    SC_THREAD(respondDrv);
   }
 
   void respondDrv()
   {
    while(true)
    printf("in respondDrv\n");
   }
};
 
 
int sc_main(int argc, char **argv)
{
printf("hello world\n");
 
SYSCMAC *q = new SYSCMAC("mac");
SYSCNETDEV *sn = new SYSCNETDEV("qemu");
 
    sc_start();
 
    printf("start simulation now\n");
return 0;
}

 

 

Hello,

Please get hold of a good reference on SystemC and read through it.

Both your modules have threads, but NONE of them are "sensitized"

to any events. That is why you just have one module running, when

both should be running. Please find out how you would use the SystemC

keyword "sensitive".

Share this post


Link to post
Share on other sites

Actually, you don't need a sensitive statement. You can simply insert:

 

  wait(1,SC_NS);

 

into each of the loops to observe the behavior.

 

In fact, I rarely use static sensitivity in my SystemC code. I prefer dynamic because it results in easier to understand code. Mind you, I don't write RTL when writing SystemC. RTL more or less requires static sensitivity.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...