thread of pools again

hi,
is what somebody can explain me how a thread of pools functions because I
will like to write a server code which makes it possible to communicate with
several customers
I tested but do not function i don´t know where is the error
by exempls: here the code


int chid, pid, rcvid;
t_Message *msg;
t_Message *r_msg;
t_serverconnectioninfo *buffer;
int fd;


//Signal action structure to handle incoming signals
struct sigaction sSignalActionDriver;



void SignalHandlerDriver(int iSignal)
{
switch(iSignal)
{
case SIGINT:
free(buffer);
free(msg);
free(r_msg);
close(fd);
ChannelDestroy(chid);
break;
default: //do nothing
break;
}
exit(0);
}


//Thread 2
void *Supserver2(void *arg)
{
int iRetValue;
time_t now;
time(&now);
printf("\t Supserver2 starting at %s \n",
ctime(&now));

//Create a space
msg = (t_Message *) malloc(sizeof(t_Message));
r_msg = (t_Message *) malloc(sizeof(t_Message));
buffer = (t_serverconnectioninfo *)
malloc(sizeof(t_serverconnectioninfo) );

printf("\t Hier bin ich gewesen\n");


if(msg == NULL)
{
printf("\t Cannot Create a Space msg2\n");
perror(NULL);
exit(EXIT_FAILURE);
}
if(r_msg == NULL)
{
printf("\t Cannot Create a Space r_msg2\n");
perror(NULL);
exit(EXIT_FAILURE);
}
if(buffer == NULL)
{
printf("\t Cannot Create a Space buffer2\n");
perror(NULL);
exit(EXIT_FAILURE);
}



//Initialize the SignalHandler for cathing Ctrl-c
sSignalActionDriver.sa_handler = SignalHandlerDriver;
sigaction(SIGINT, &sSignalActionDriver, NULL);

//to get a channel ID
if( (chid = ChannelCreate(0)) == -1)
{
#ifdef _DEBUG_SERVER
printf(“error by creating channel: Error[%d]
Meaning[%s]\n”,
errno, strerror(errno));
#endif
return 0;
}

//to get a process ID
pid = getpid();

//open a file in etc
fd = open("/etc/msg_passing_data1.dat", O_WRONLY |
O_CREAT, 777);
if(fd == 0)
{
printf("\t ERROR, cannot open the file client\n");
perror(NULL);
exit( EXIT_FAILURE);
}


//initialize a Value Buffer
buffer->pid = pid;
buffer->chid = chid;

//write in the file msg_passing_data.dat
if( (iRetValue = write(fd, (void*) buffer,
sizeof(t_serverconnectioninfo) ) ) == -1)
{
perror(“Fehler beim Write in client.dat”);
exit( EXIT_FAILURE);
}

//start a Server
printf("\n\t+++++++++++++++++++++++++\n");
printf("\t SUBSERVER 2 GESTARTET\n");
printf("\t+++++++++++++++++++++++++\n\n");

while(1)
{
rcvid = MsgReceive(chid, r_msg, sizeof(t_Message),
NULL);

printf("\t rcvid = %d \n", rcvid);

if(rcvid == -1)
{
printf("\t Fatal Error MsgReceive Failed\n");
exit(EXIT_FAILURE);
}

else
{
printf("\t SubServer: hat identifier the NAME is %s
\n", r_msg->name);
strncpy(msg->type, “Subserver”, MAX_NAME_LENGTH);
strncpy(msg->name, “Reply Subserver”,
MAX_NAME_LENGTH);
//sleep(5);
MsgReply(rcvid, 1 , msg, sizeof(t_Message));
}
} // end of while(1)

return EXIT_SUCCESS;
}


//main Thread
int main(int argc, char *argv[])
{
//int iRetValue;
time_t now;
thread_pool_t *tpp;
thread_pool_attr_t pool_attr;
dispatch_t *dpp;
//resmgr_attr_t resmgr_attr;



if( (dpp = dispatch_create()) == NULL )
{
fprintf( stderr, “%s: Unable to allocate dispatch
context.\n”, argv[0] );
perror(NULL);
return EXIT_FAILURE;
}

memset( &pool_attr, 0, sizeof (pool_attr));
pool_attr.handle = dpp;
/* We are only doing resmgr-type attach */
// pool_attr.context_alloc = resmgr_context_alloc;
// pool_attr.block_func = resmgr_block;
// pool_attr.handler_func = resmgr_handler;
//pool_attr.context_free = resmgr_context_free;
pool_attr.lo_water = 2;
pool_attr.hi_water = 4;
pool_attr.increment = 1;
pool_attr.maximum = 50;


if( (tpp = thread_pool_create( &pool_attr,
POOL_FLAG_EXIT_SELF )) == NULL )
{
fprintf( stderr, “%s: Unable to initialize thread
pool.\n”, argv[0] );
perror(NULL);
return EXIT_FAILURE;
}
time(&now);
printf("\t main() starting at %s \n", ctime(&now));

pthread_create( NULL, NULL, Supserver2, NULL );


sleep(10);
//Pool Startet
thread_pool_start( tpp );


return EXIT_SUCCESS;
}

thanks

You set up a thread pool, and then create a thread.
The thread creates a channel and then handles messages sequentially.
The thread pool is started, but it hasn’t been set up to do anything.
So what did you want to happen?

This can all be quite confusing since there are a few layers
involved.
Typically a thread pool is used with a resource manager that attaches
name space, something like “/dev/myresource”. QNX gives
you a
layer that provides support for Posix calls, such as open(), close(),
read(), write(),
which you can override as needed. Above this layer is a dispatch
layer.
The dispatch layer routes incoming messages either to the resource
layer,
or for custom messages, to your custom routines. The thread pool
feature
can be added to the dispatch layer to provide a multi-threaded
resource
manager, although you must write code that protects against code that
is
not thread safe. This might be updating a memory structure
connected
by pointers. I would not try to figure out how to implement all
this by
just reading the routine documentation. Instead, start with some
examples
in the documentation, and enhance them. Also Robert Krten’s book on
this
subject is good, although I don’t know if it is easily available
anymore.

please could you give me an example how to make walk Thread Pool to carry
out a connection where several customers can communicate with only one
server at the same time



“maschoen” <maschoen@pobox-dot-com.no-spam.invalid> schrieb im Newsbeitrag
news:f4uji2$akr$2@inn.qnx.com

You set up a thread pool, and then create a thread.
The thread creates a channel and then handles messages sequentially.
The thread pool is started, but it hasn’t been set up to do anything.
So what did you want to happen?

This can all be quite confusing since there are a few layers
involved.
Typically a thread pool is used with a resource manager that attaches
name space, something like “/dev/myresource”. QNX gives
you a
layer that provides support for Posix calls, such as open(), close(),
read(), write(),
which you can override as needed. Above this layer is a dispatch
layer.
The dispatch layer routes incoming messages either to the resource
layer,
or for custom messages, to your custom routines. The thread pool
feature
can be added to the dispatch layer to provide a multi-threaded
resource
manager, although you must write code that protects against code that
is
not thread safe. This might be updating a memory structure
connected
by pointers. I would not try to figure out how to implement all
this by
just reading the routine documentation. Instead, start with some
examples
in the documentation, and enhance them. Also Robert Krten’s book on
this
subject is good, although I don’t know if it is easily available
anymore.

ouoguep jerome <ouoguep@hotmail.com> wrote:

please could you give me an example how to make walk Thread Pool to carry
out a connection where several customers can communicate with only one
server at the same time

A “QNX Thread Pool” (thread_pool_*()) does more than that. But if you
only want a “pool of thread” to handle multiple customer request, then,
just create a punch of server thread …

In your example, there is a “while(1){}” loop which is you server,
put that loop in a function, and create more threads with that function,
basically that’s all you need.

-xtang

“maschoen” <> maschoen@pobox-dot-com.no-spam.invalid> > schrieb im Newsbeitrag
news:f4uji2$akr$> 2@inn.qnx.com> …
You set up a thread pool, and then create a thread.
The thread creates a channel and then handles messages sequentially.
The thread pool is started, but it hasn’t been set up to do anything.
So what did you want to happen?

This can all be quite confusing since there are a few layers
involved.
Typically a thread pool is used with a resource manager that attaches
name space, something like “/dev/myresource”. QNX gives
you a
layer that provides support for Posix calls, such as open(), close(),
read(), write(),
which you can override as needed. Above this layer is a dispatch
layer.
The dispatch layer routes incoming messages either to the resource
layer,
or for custom messages, to your custom routines. The thread pool
feature
can be added to the dispatch layer to provide a multi-threaded
resource
manager, although you must write code that protects against code that
is
not thread safe. This might be updating a memory structure
connected
by pointers. I would not try to figure out how to implement all
this by
just reading the routine documentation. Instead, start with some
examples
in the documentation, and enhance them. Also Robert Krten’s book on
this
subject is good, although I don’t know if it is easily available
anymore.

I made a success of finalemnt with carried out this connection by using the
multithreads in the function main thank you for the assistance


<xtang@qnx.com> schrieb im Newsbeitrag news:f575q5$gg1$1@inn.qnx.com

ouoguep jerome <> ouoguep@hotmail.com> > wrote:
please could you give me an example how to make walk Thread Pool to carry
out a connection where several customers can communicate with only one
server at the same time

A “QNX Thread Pool” (thread_pool_*()) does more than that. But if you
only want a “pool of thread” to handle multiple customer request, then,
just create a punch of server thread …

In your example, there is a “while(1){}” loop which is you server,
put that loop in a function, and create more threads with that function,
basically that’s all you need.

-xtang




“maschoen” <> maschoen@pobox-dot-com.no-spam.invalid> > schrieb im
Newsbeitrag
news:f4uji2$akr$> 2@inn.qnx.com> …
You set up a thread pool, and then create a thread.
The thread creates a channel and then handles messages sequentially.
The thread pool is started, but it hasn’t been set up to do anything.
So what did you want to happen?

This can all be quite confusing since there are a few layers
involved.
Typically a thread pool is used with a resource manager that attaches
name space, something like “/dev/myresource”. QNX gives
you a
layer that provides support for Posix calls, such as open(), close(),
read(), write(),
which you can override as needed. Above this layer is a dispatch
layer.
The dispatch layer routes incoming messages either to the resource
layer,
or for custom messages, to your custom routines. The thread pool
feature
can be added to the dispatch layer to provide a multi-threaded
resource
manager, although you must write code that protects against code that
is
not thread safe. This might be updating a memory structure
connected
by pointers. I would not try to figure out how to implement all
this by
just reading the routine documentation. Instead, start with some
examples
in the documentation, and enhance them. Also Robert Krten’s book on
this
subject is good, although I don’t know if it is easily available
anymore.