Hi, I am programming some console application that updates itself periodically from Internet. (windows.h + pthreads for win32) I want to do something like: [CODE] MAIN FUNCTION: create thread launch updater THREAD: infinite loop - starts the main application, exits if application ended normally but when it was killed by updater, start it again. UPDATER: checks, if updates are available → kill main app and download new version. [/CODE] To the application, I need a PROCESS_INFORMATION pi, but: when i define it globally, the THREAD function freezes when tryiing to CreateProcess. when i tried to define it like a pointer, …

Member Avatar
Member Avatar
+0 forum 3

In a unix pthreads based app I'm working on, I have objects of a particular class (call it class foo) being created in multiple threads. I need a specific public method of class foo invoked at or after 60 seconds of the object coming into existence (it is not imperative that it happens at precisely 60s, just that it happens at either 60s or very shortly thereafter). Any ideas on what thread-safe timers are available that could I use to achieve this? Looking for either something that I could just drop right in to my class foo or which I …

Member Avatar
Member Avatar
+0 forum 6

Can anyone help me improve my source code below? I tried fixing it but apparently, there's not much success. [CODE] #define NUM_THREADS1 1 void *go_to_website2(void *program); void *go_to_website1(void *program) { char* str[3]; str[0] = (char *)program; str[1] = "http://www.google.com"; //supposedly 2nd website to go to str[2] = '\0'; char* new_prog = "firefox"; pthread_t th; int rc2; rc2 = pthread_create(&th, NULL, go_to_website2, (void *)new_prog); //2nd thread created pthread_join(th, NULL); //wait for the second thread th to be finished execvp(str[0], str); //go to 2nd website (google.com), unsuccessfully opened } void *go_to_website2(void *program) { char* str2[3]; str2[0] = (char *)program; str2[1] = "http://www.yahoo.com"; …

Member Avatar
Member Avatar
+0 forum 8

Hi, I would like to make an threaded app which would use pthreads. I made a linked list and I put references to running threads here. I know that operations of adding a new thread reference to the list and removing a thread reference from the list after the thread finishes has to be mutexed. I just want to ask if I made the mutexes in right way. So only one thread can remove or add new item to the list. Lines 10-12 and 31-36. [CODE]/** * */ void *run_thread(void *soc) { t->number = (int) pthread_self(); printf("%d\n", t->number); /* unimportant …

Member Avatar
Member Avatar
+0 forum 2

Hi all, Is there a way to make thread pools in POSIX pthreads? (using c) I could only find implementations for java and c++, but I need it to be in c. Thanks.

Member Avatar
Member Avatar
+0 forum 3

Hi all, I have a multithreaded program, one of the threads needs to listen for user input. I was wondering is there a way of checking for user input every few seconds or milliseconds, without having the thread hang on a fgets() function? Current I have: [CODE] while(keep_running == TRUE) { usleep(25); char command[80]; fgets(command,80,stdin); /* handle input */ }[/CODE] I want to change fgets(command,80,stdin); to something that checks for users input and not waits on user input.

Member Avatar
Member Avatar
+0 forum 5

Hi all, I'm making a miltithreaded program that uses the pthreads library. One of the threads monitors the users input. my problem is when I enter a close command I get the following error: 9 [sig]...: *** fatal error - called with threadlist_ix -1 make: *** [run] Hangup I know it only happens when I free some memory I have allocated at the start of the program. Here is the problem code: [CODE] //lock to protect buffer pthread_mutex_lock(&mutex); //free memory for(int i = 0; i < ST_SIZE; ++i) { free(st.buffer[i]); } //unlock pthread_mutex_unlock(&mutex);[/CODE] Any hints? thanks.

Member Avatar
+0 forum 0

The End.