In order to create an RT-thread from another RT-thread, you need to
pre-allocate a stack and pass it to pthread_create via
pthread_attr_setstackaddr/pthread_attr_setstacksize
(examples/misc/create_recursive.c). This is supported in RTLinux
3.1 prereleases.
Otherwise, pthread_create will try to use a Linux memory allocation routine,
kmalloc, use of which is unsafe in RT-threads.
Michael.
Thomas Sauter ([EMAIL PROTECTED]) wrote:
> Hi folks,
>
> I'm sorry for bother you, but using nanosleep in rtlinux_3.0 causes some
> strange behavior. The added code is supposed to toggle bit 0 off a
> digital-io-card. The idea was to create a thread with a free running
> while loop in wich a other thread is created and joined periodically.
> After compiling and running the module it will work a view seconds and
> then the system will crash. I'm not used in working with threads and
> maybe there is a mistake using them. If somebody can see the error
> please help me!
>
> #include <linux/module.h>
> #include <linux/kernel.h>
> #include <linux/version.h>
> #include <linux/errno.h>
> #include <rtl_sched.h>
> #include <rtl_fifo.h>
> #include <linux/cons.h>
>
> // headers for using multi-io-card, generating the signal
> #include "win_ddk_types.h"
> #include "pdfw_def.h"
> #include "powerdaq-internal.h"
> #include "powerdaq.h"
> #include "pdfw_if.h"
>
> #define UPTIME 100000
> #define DOWNTIME 100000
>
> pthread_t main_thr, trigger_thr;
> unsigned int dout=0;
> int board_handle=1;
>
> void *trigger(void *dummy)
> {
> pd_dout_write_outputs(board_handle, dout|=(1<<0));
> nanosleep(hrt2ts(UPTIME), NULL);
> pd_dout_write_outputs(board_handle, dout&=~(1<<0));
> return NULL;
> }
>
> void *mainthread(void *dummy)
> {
> while(1)
> {
> pthread_create(&trigger_thr, NULL, trigger, NULL);
> pthread_join(trigger_thr, NULL);
> //pthread_delete_np(trigger_thr);
> nanosleep(hrt2ts(DOWNTIME), NULL);
> }
>
> return NULL;
> }
>
> int init_module(void)
> {
> pthread_create(&main_thr, NULL, mainthread, NULL);
> return 0;
> }
>
> void cleanup_module(void)
> {
> pthread_delete_np(main_thr);
> }
>
> --
> Thomas Sauter Tel. 06221/75933-15
> 20/10 Perfect Vision [EMAIL PROTECTED]
> Waldhofer Str. 100
> D-69123 Heidelberg
>
> ----- End of forwarded message from [EMAIL PROTECTED] -----
> -- [rtl] ---
> To unsubscribe:
> echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
> echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
> --
> For more information on Real-Time Linux see:
> http://www.rtlinux.org/
----- End of forwarded message from [EMAIL PROTECTED] -----
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
--
For more information on Real-Time Linux see:
http://www.rtlinux.org/