Hi,
I have a question about POSIX threads programming regarding
the program below. Basically, I have 3 threads that are doing nothing
but printing a message and a 4th thread which continuously loop until
all the other 3 threads terminate. To check that the other 3 threads
terminate properly, the 4th thread make calls to
pthread_getschedparam(). I tested the code on a machine running FreeBSD
5.3 and everything works fine. However, the behavior of the program is
completely different on machines running Linux or Cygwin. The problem
on those machines is that pthread_getschedparam() does not return the
proper error code (ESRCH) even when the thread id that was passed to it
is no longer running. I did notice however, that when I moved the code
for the 4th process into main(), everything works fine, which seems to
suggest that only parent process can access their child threads'
scheduling state. So, my questions are:
1) In the POSIX thread
implementation on Linux/Cygwin, can threads running within the same
process access the scheduling state of their peers via
pthread_getschedparam()?
2) Am I just doing something stupid by calling pthread_getschedparam() within my 4th thread ?
Below is the code in question:
#include <stdio.h>
#include <pthread.h>
#include <sched.h>
#include <sys/errno.h>
#define NUM_RECEIVERS 3
pthread_t rxThread[NUM_RECEIVERS];
pthread_t computeThread ;
void *rxThreadFunc(void *arg)
{
int *i ;
i = (int *)arg ;
printf("Inside Thread %d\n", *i);
return NULL ;
}
void *computeThreadFunc(void *arg)
{
int p[NUM_RECEIVERS] ;
int k;
int flag ;
struct sched_param s[NUM_RECEIVERS] ;
while(1)
{
flag = 1 ;
for( k=0; k < NUM_RECEIVERS; k++ )
{
if( pthread_getschedparam(rxThread[k], &(p[k]), &(s[k])) == ESRCH )
continue ;
else
{
printf("Policy = %d\n", p[k]);
flag = 0 ;
break ;
}
}
if( flag == 1 )
{
printf("ALL THREADS HAVE STOPPED\n") ;
break ;
}
else
{
printf("SOME THREADS ARE STILL RUNNING\n");
}
}
return NULL ;
}
int main()
{
int j, k;
int p ;
struct sched_param s ;
for( j=0; j < NUM_RECEIVERS; j++ )
{
if( pthread_create(&(rxThread[j]), NULL, rxThreadFunc, &j) != 0 )
{
printf("Thread #%d was not created\n", j);
for( k=0; k < j; k++ )
pthread_cancel(rxThread[j]);
}
pthread_join(rxThread[j], NULL) ;
}
if( pthread_create(&computeThread, NULL, computeThreadFunc, NULL) != 0 )
{
printf("computeThread not created :-(\n");
for( k=0; k < NUM_RECEIVERS; k++ )
pthread_cancel(rxThread[j]);
}
pthread_join(computeThread, NULL);
return 0 ;
}
____________________________________________________________________________________
Get the free Yahoo! toolbar and rest assured with the added security of spyware protection.
http://new.toolbar.yahoo.com/toolbar/features/norton/index.php
---------------------------------------------------------------------
To unsubscribe, e-mail: opensuse-programming+unsubscribe(a)opensuse.org
For additional commands, e-mail: opensuse-programming+help(a)opensuse.org
Hi there
when i compile my kdevelop-projekt (simple C++ in console-mode) in
"debug"-mode, i get a filesize of 300 KB, because of the debug-code insight.
when i compile the same to "optimized"-mode, i get a smaller filesize of
the executable of 40 KB.
for making a dist i copied the whole project-folder to a temporary
directory and run "make dist".
then i was testing this distribution:
i unpacked this zipped tarball to a directory, called there
"./configure", "make" and "make install". everything worked fine.
but: the compiled and installed executable now has a size of 170 KB, so
this is neither the debug-mode nor the optimized-mode.
what should i do, that the dist-copy would compiled like in
"optimized"-mode from kdevelop?
what compiler- and linker-options could be within the dist?
thank you very much for any help!
kind regards
hagen
---------------------------------------------------------------------
To unsubscribe, e-mail: opensuse-programming+unsubscribe(a)opensuse.org
For additional commands, e-mail: opensuse-programming+help(a)opensuse.org
Hello list,
I'd like to compile a 32-bit kernelmodule (ndiswrapper) on a 64-bit (AMD)
System. My idea is to use the 32-bit runtime environment because I've got
only a 32-bit Driver for a wlan card. The manufacturer is not planning to
release a 64-bit driver for that card. Will my idea work and where do I find
information about compiling 32-bit software on a 64-bit linux box using gcc?
Best Regards,
Oliver
---------------------------------------------------------------------
To unsubscribe, e-mail: opensuse-programming-de+unsubscribe(a)opensuse.org
For additional commands, e-mail: opensuse-programming-de+help(a)opensuse.org
---------------------------------------------------------------------
To unsubscribe, e-mail: opensuse-programming+unsubscribe(a)opensuse.org
For additional commands, e-mail: opensuse-programming+help(a)opensuse.org
I have a static string defined in a class:
class Foo
{
public:
...
static const std::string default_name;
...
};
In the C++ file:
const std::string Foo::default_name("standard");
The C++ file is compiled into a shared library, say libfubar.so
The executable is built:
g++ main.cc -o fubar -L<path to libraries> -lfubar
In the real case I have about a dozen libraries. To execute the code, I
manually update LD_LIBRARY_PATH to point to the shared libraries
including the RogueWave STL implementation, but I segfault in
std::string when it is accessing Foo::default_name.
I have tested with and without const. The backtrace shows that we are
in the default constructor, Foo().
As a work around, I could possibly use a c language string (eg. char
*), or even simply define the string as a manifest constant, but my
preference is to use the STL string.
--
Jerry Feldman <gaf(a)blu.org>
Boston Linux and Unix user group
http://www.blu.org PGP key id:C5061EA9
PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9