03-17-2008
I agree with
-------------------------------------------------------------
I'd recommend you to re-design of your software with producer and worker concept. One thread will read data on socket then it will select a thread from pool and assign work to that.
----------------------------------------------------------------
10 More Discussions You Might Find Interesting
1. Programming
Hi,
I want to validate that a file is a socket file on Linux. I know I can do this using the S_ISSOCK macro, but I am not sure how to get the file descriptor for the socket file.
For example, I know that /tmp/mapping-foo is a socket file. In Python I can do something like this:
>>> import... (2 Replies)
Discussion started by: goon12
2 Replies
2. Programming
I have set the receive buffer size of socket to max.
setsockopt(sd,SOL_SOCKET, SO_RCVBUF,&max,optval);
Am reading data from the socket in a loop(say max 100 bytes per recv)
while(1)
{
int rlen=recv(sd,(void *)buf, 100 , 0);
//err handle and processing
}
Assume my process is slow... (2 Replies)
Discussion started by: johnbach
2 Replies
3. Solaris
Hi All
I have a separate thread ListenerThread having a socket listening to info broadcasted by some remote server. This is created in my main thread.
Because of requirements, once the separate thread is started I need to avoid any blocking function on the main thread. Once it comes to the... (2 Replies)
Discussion started by: manustone
2 Replies
4. Solaris
I have a query related to the functioning of poll() system call on solaris and linux platforms.
When the client is abnormally terminated, it is observed that on Linux the socket is immediately closed and the server gets ECONNREFUSED.
But in case of Solaris it is observed that the socket is not... (0 Replies)
Discussion started by: Amarjeet_7
0 Replies
5. Programming
char name;
printf ("Welcome to the server \n");
printf ("Enter user name: \n");
scanf ("%c", &name);
how can client send name to server:what should be the code?
int send ( int sid , const char ∗buffer Ptr , int len , int f l a g )
how can client receive ack from... (1 Reply)
Discussion started by: saiful_911
1 Replies
6. Programming
How to know whether socket is ready for write.
select(maxfds, (fd_set *)NULL, &writefds, NULL, &timeout);
By default socket is set for write without checking whether it would block or not? If so how do I know my FD is ready for writing. (3 Replies)
Discussion started by: satish@123
3 Replies
7. Programming
Hi all,
Can I create multiple threads using single thread_id
like
pthread_t thread_id;
pthread_create(&thread_id, NULL, &print_xs, NULL);
pthread_create(&thread_id, NULL, &print_ys, NULL);
pthread_create(&thread_id, NULL, &print_zs, NULL);
pthread_join(thread_id, NULL);
what... (2 Replies)
Discussion started by: zing_foru
2 Replies
8. IP Networking
Hello to all,
I have below function, but the thread will be bloked at the line
delete pListenSocket; // Close and delete
If I put some cpu timing switching function prior to it, then no blocking pop up.
printf("xyz\n"); // or sleep(100);
delete pListenSocket; // Close and... (1 Reply)
Discussion started by: shinypro
1 Replies
9. Solaris
I have BIND 9.8.1-P1 cache only DNS server running in Solaris 10. I have upgraded the same from 9.6.1 to 9.8.1-P1. Now i am facing "file descriptor exceeds limit (4096/4096)" error frequently on the server.
Please help me on this issue! (1 Reply)
Discussion started by: sandeep.tk
1 Replies
10. Shell Programming and Scripting
Hi,
Input
7488 7389 chr1.fa chr1.fa
3546 9887 chr5.fa chr9.fa
7387 7898 chrX.fa chr3.fa
7488 7389 chr21.fa chr3.fa
7488 7389 chr1.fa chr1.fa
3546 9887 chr9.fa chr5.fa
7898 7387 chrX.fa chr3.fa
Desired Output
7488 7389 chr1.fa chr1.fa 2
3546 9887 chr5.fa chr9.fa 2... (2 Replies)
Discussion started by: jacobs.smith
2 Replies
LEARN ABOUT DEBIAN
iv_work_pool_create
iv_work(3) ivykis programmer's manual iv_work(3)
NAME
IV_WORK_POOL_INIT, iv_work_pool_create, iv_work_pool_put, IV_WORK_ITEM_INIT, iv_work_pool_submit_work - ivykis worker thread management
SYNOPSIS
#include <iv_work.h>
struct iv_work_pool {
int max_threads;
void *cookie;
void (*thread_start)(void *cookie);
void (*thread_stop)(void *cookie);
};
struct iv_work_item {
void *cookie;
void (*work)(void *cookie);
void (*completion)(void *cookie);
};
void IV_WORK_POOL_INIT(struct iv_work_pool *this);
int iv_work_pool_create(struct iv_work_pool *this);
int iv_work_pool_put(struct iv_work_pool *this);
void IV_WORK_ITEM_INIT(struct iv_work_item *work);
int iv_work_pool_submit_work(struct iv_work_pool *this, struct iv_work_item *work);
DESCRIPTION
Calling iv_work_pool_create on a struct iv_work_pool object previously initialised by IV_WORK_POOL_INIT creates a pool of worker threads
that can be used to offload CPU intensive tasks to, so as to prevent negatively influencing event handling latency in the calling thread,
and to enable the use of multiple host CPUs for CPU intensive tasks.
iv_work dynamically adjusts the number of threads in the pool to the amount of work there is to do. The ->max_threads member of struct
iv_work_pool specifies the maximum number of threads that will be created in this pool.
Calling iv_work_pool_submit_work on a struct iv_work_item object previously initialised by IV_WORK_ITEM_INIT submits a work item to a pool.
The ->work member of struct iv_work_item specifies the function that will be called in one of the worker threads in the pool specified by
->this, with ->cookie as its sole argument. When the work function has completed, iv_work will call the ->completion callback to indicate
this, also with ->cookie as its sole argument, in the thread that iv_work_pool_create was called in for this pool object.
As a special case, calling iv_work_pool_submit_work with a NULL work pool pointer will cause the work item to be processed in the local
thread, from an iv_task(3) callback.
If the ->thread_start function pointer specified in struct iv_work_pool is not NULL, it will be called upon creation of a new worker
thread, in the context of the created worker thread, with ->cookie as its sole argument. Calls to ->thread_start are not explicitly seri-
alised, which should be kept in mind when manipulating state shared between threads from within that callback function.
Similarly, if iv_work decides to terminate a worker thread, for example due to inactivity, ->thread_stop will be called in the context of
the terminating thread, with ->cookie as its sole argument. Calls to ->thread_stop are also not explicitly serialised.
iv_work_pool_submit_work can only be called from the thread that iv_work_pool_create for this pool object was called in.
There is no way to cancel submitted work items.
There is no guaranteed order, FIFO or otherwise, between different work items submitted to the same worker thread pool.
When the user has no more work items to submit to the pool, its reference to the pool can be dropped by calling iv_work_pool_put.
If there are still pending or running work items assigned to this pool when iv_work_pool_put is called, those work items will not be can-
celed, but will be allowed to run to completion, and their ->completion callbacks will be called as usual. A similar thing holds for the
->thread_start and ->thread_stop callbacks -- they can also still be called after iv_work_pool_put returns. Even so, the memory corre-
sponding to the struct iv_work_pool can immediately be freed or reused by the user upon return of the iv_work_pool_put call.
Internally, iv_work uses iv_thread(3) for its thread management.
SEE ALSO
ivykis(3), iv_thread(3)
ivykis 2010-09-14 iv_work(3)