[RkWard-devel] C stack usage is too close to the limit

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Mon Jun 26 08:54:29 UTC 2006


Hi Mattew,

you mean an application other than rkward? RKWard should have this solved 
since release 0.3.6 (but you might have to recompile after upgrading from R 
2.2.x to R 2.3.x).

Assuming you're not talking about RKWard: 
1) This should not happen with R 2.2.1. Are you sure, you compiled against the 
correct installation of R? As far as I know, R 2.2.1 does not even have any 
stack checking. You might try to grep the libR.so for "C stack usage is" to 
verify.

2) Stack checking in R 2.3.x does not get initialized correctly, when run from 
a thread which is not the main application thread. RKWard now uses roughly 
this startup code:

extern int Rf_initEmbeddedR(int argc, char **argv);
extern int Rf_initialize_R(int ac, char **av);
extern void setup_Rmainloop(void); /* in main.c */
extern unsigned long R_CStackLimit; /* defined in RInterface.h for R 2.3.1 but 
not for R 2.3.0 */

#if (R_VERSION > R_Version(2, 2, 9))
	Rf_initialize_R (argc, argv);
	R_CStackLimit = (unsigned long) -1; 	/* disables R stack checking entirely */
	setup_Rmainloop ();
	return true;
#else
	bool ok = (Rf_initEmbeddedR (argc, argv) >= 0);
	return ok;
#endif

Note that you can't use Rf_initEmbeddedR () in this case, as the stack 
checking needs to be disabled before setup_Rmainloop () is called (does not 
make much of a difference, though, as - at least for now - Rf_initEmbeddedR 
() simply calls Rf_initialize_R () and setup_Rmainloop ().
Of course you could also adjust the R_CStackStart to a meaningful value 
instead of disabling the stack checking entirely.

3) I'm curious: What application are you working on?

Hope this helps
Thomas

On Monday 26 June 2006 07:23, Matthew Fulcher wrote:
> I am getting a seg fault and the following error when trying to use an
> embedded version of R in a multithreaded application.
>
> Error: C stack usage is too close to the limit
>
> When I do the same thing in a single threaded app, then there is no
> problem.
> I've tried this with R version 2.3.0, 2.3.1 and even 2.2.1 and the same
> error occurs.
> Any tips on how to solve this?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/rkward-devel/attachments/20060626/9dddadf9/attachment.sig>


More information about the Rkward-devel mailing list