[HELP ME]Questions with thread!

In QNX4.25. One of my process( prcsGet ) forked a child thread, such as thdAnalyze.In thdAnalyze’s main function( thdAnalyze() ), it called
another function( AnalyzePacket() ), and NextAnalyzation() were called further. As bellowing:

My questions:

  1. What will happen if both AnalyzePacket() and NextAnalyzation() waste a long time but other processes trigger my_rx_proxy quickly?
    Is it possible that more than one AnalyzePacket() or NextAnalyzation() functions are running at some same time?

  2. The size of the stack of thdAnalyze thread is 4*4096 Bytes, that is, 16KB.
    If i defined lots of variables, will the stack of thdAnalyze thread overflow?

  3. Sometimes i compiled my code, i was told that the code segment was too smaller to load it.
    What can i do for that?

Thanks in advance.

Fork a child thread? You mean with tfork? Words of warning, threads and QNX4 don’t mix well.

1 ) Proxy are queued. You don’t provide enough code to answer the second part of that question. Nothing ever gets run at the same time unless you have 2 CPU. But yes threads/processes to get time sliced.

  1. Strange question, you kind of answered it yourself. I would guestimate you need at least 100 bytes of stack just to get you started. Then average 20 bytes per function call (per level) plus the size of the local variable and that will give you an idea of how much stack you need.

  2. huh? Are you compiling in 16 bits mode? What message do you get and at what step?

Dear Mario.

  1. If both AnalyzePacket() and NextAnalyzation() functions waste a long time but other processes trigger my_rx_proxy quickly, will the resource of CPU used by theAnalyze thread be more and more?

  2. I think that the compiler will warn me when i compile the codes if the stack of thread may overflow.Because the compiler can compute the size of the total variable and functions, and if this size if larger than the size of the stack i applied, the compiler should warn me.

  3. There are more than 10 files included in one of my source file.When i compiled them by makefile, i was told “*** FATAL *** segment too large”.

  1. Well kind of. If AnalysePacket takes 100ms to do it’s work and the proxy is trigger every 90ms, Analyse Packet will use all the CPU (if priority allows it) because as soon as it finish Receive will return immedialtely because proxy are queued. QNX will NOT dynamical change the priority of the help AnalysePacket to faster, assuming it’s slow down by higher priority process.

2 ) No compiler will not warn you, that would be extremely complexe because the compiler would have to “execute the code” in order to figure it out. A recursive function is a good example of that, the compiler would need to calculate out how much time the function would call itself to tell how much stack is being used. Plus you have code in libraries that compiler doesn’t know about. Stack usage is not only about number of auto variable (what about calls to alloca() made with a variable instead of a constant)

3 ) That is probably because you compile with debug on. The default debug format is limited to 64k segment (what ever that means) try -g2d instead to switch to dwarf format.

You didn’t say if you are using thread. If you do, given the type of question you are asking which tells me you don’t have much experience with QNX, you should really, really avoid threads unless you got plenty of time available.

Thank you for your answer, Mario.
I have to use threads.
2) Sometimes i was told that “/home/…/ProgramA terminate at ********”. What that means? The Stack overflows, or a wrong operation with memorys?

What makes you think you have to use threads. Last warning Hmilzy, stay way from threads under QNX4, i’m not kidding.

1 ) Could be both. If you want to know if it’s not the stack, increase stack size to 1Meg.