diff --git a/rt-thread-version/rt-thread-standard/programming-manual/ipc2/figures/07signal_enable.png b/rt-thread-version/rt-thread-standard/programming-manual/ipc2/figures/07signal_enable.png new file mode 100644 index 0000000000000000000000000000000000000000..7830aadbd5118f231918044862c3892772f621de Binary files /dev/null and b/rt-thread-version/rt-thread-standard/programming-manual/ipc2/figures/07signal_enable.png differ diff --git a/rt-thread-version/rt-thread-standard/programming-manual/ipc2/ipc2.md b/rt-thread-version/rt-thread-standard/programming-manual/ipc2/ipc2.md index 48d223430878b41fa14d31c74d7cba1e9732f5ff..a04ad69779a64b1b58f532ece4bcbdc215ed0a54 100644 --- a/rt-thread-version/rt-thread-standard/programming-manual/ipc2/ipc2.md +++ b/rt-thread-version/rt-thread-standard/programming-manual/ipc2/ipc2.md @@ -595,19 +595,23 @@ rt_ssize_t rt_mq_recv (rt_mq_t mq, void* buffer, **消息队列的使用例程** -> 注意:RT-Thread 5.0 及更高的版本将 `ALIGN` 关键字改成了 `rt_align`,使用时注意修改。 - ```c #include +#define THREAD1_PRIORITY 25 +#define THREAD1_STACK_SIZE 512 +#define THREAD1_TIMESLICE 5 + +#define THREAD2_PRIORITY 25 +#define THREAD2_STACK_SIZE 512 +#define THREAD2_TIMESLICE 5 + /* 消息队列控制块 */ static struct rt_messagequeue mq; /* 消息队列中用到的放置消息的内存池 */ static rt_uint8_t msg_pool[2048]; -ALIGN(RT_ALIGN_SIZE) -static char thread1_stack[1024]; -static struct rt_thread thread1; +static rt_thread_t tid1 = RT_NULL; /* 线程 1 入口函数 */ static void thread1_entry(void *parameter) { @@ -633,9 +637,8 @@ static void thread1_entry(void *parameter) rt_mq_detach(&mq); } -ALIGN(RT_ALIGN_SIZE) -static char thread2_stack[1024]; -static struct rt_thread thread2; + +static rt_thread_t tid2 = RT_NULL; /* 线程 2 入口 */ static void thread2_entry(void *parameter) { @@ -700,21 +703,23 @@ int msgq_sample(void) return -1; } - rt_thread_init(&thread1, - "thread1", - thread1_entry, - RT_NULL, - &thread1_stack[0], - sizeof(thread1_stack), 25, 5); - rt_thread_startup(&thread1); + /* 动态创建线程1 */ + tid1 = rt_thread_create("thread1", + thread1_entry, RT_NULL, + THREAD1_STACK_SIZE, + THREAD1_PRIORITY, THREAD1_TIMESLICE); - rt_thread_init(&thread2, - "thread2", - thread2_entry, - RT_NULL, - &thread2_stack[0], - sizeof(thread2_stack), 25, 5); - rt_thread_startup(&thread2); + if (tid1 != RT_NULL) + rt_thread_startup(tid1); + + /* 动态创建线程2 */ + tid2 = rt_thread_create("thread2", + thread2_entry, RT_NULL, + THREAD2_STACK_SIZE, + THREAD2_PRIORITY, THREAD2_TIMESLICE); + + if (tid2 != RT_NULL) + rt_thread_startup(tid2); return 0; } @@ -968,6 +973,10 @@ int rt_signal_wait(const rt_sigset_t *set, 这是一个信号的应用例程,如下代码所示。此例程创建了 1 个线程,在安装信号时,信号处理方式设为自定义处理,定义的信号的处理函数为 thread1_signal_handler()。待此线程运行起来安装好信号之后,给此线程发送信号。此线程将接收到信号,并打印信息。 +> 注意:使用信号前需要先在menuconfig中使能 + +![信号量使能](figures/07signal_enable.png) + **信号使用例程** ```c