Programming :: C / C++ - Shared Array Accessed Without Locking
Oct 24, 2010
If I have two threads working on the same array but on different sections of the array, can they both write and read from it without locks and not have any sort of problem? If they only use completely different parts of the array always without affecting the other part?
I'm writing a PHP program. I've encountered a problem; in the following code I try to pass $_POST['delete'] which is an array as the value of a hidden input to some form, but it doesn't do so.there's something wrong with converting PHP array into HTML array. I'm sure that $_POST['delete'] is not null and is a real array.
I want to create a "Shared Memory" in linux, then create multiple "Shared Objects" that can access to a Table for example; And one of them can write something into the Table and the other can access and read it, so that these operations can be handled by programmer! I'm using Ubuntu 9.04 and I've set it's runlevel at 3 (I have commandline environment now!) I've searched the Internet so much, but couldn't find a good sample code for this! I have no experience about it and need your help to introduce me a sample code about it and advise me how to compile and use it with "GCC"?!
(I am using vector() and matrix() functions from "Numerical recipes in C".)There are 100 numbers to be stored in 2D array of 10 rows and 10 columns.100 numbers are stored in a 1D array.I get "segmentation fault" at the line indicated in the segment of my code below:
I am going to write two or more programs that will take control of the same resources on Linux. What are the common methods/functions that can do locks/synchronizations in C?
I looked on the net for such function or example and didin't find anything, thus after having made one i guess it would be legitimate to drop it to see what others thinks of it.
#!/bin/bash addelementtoarray() { local arrayname=$1
locking mutex (phtread_t type) in a signal handler function (installed by function signal()) for Linux. It seems that if the mutex has been previously locked by another thread outside the signal handler function and then the signal handler function tries to lock it, the whole process hangs.
I have a linked list that two threads work on simultainiousley.The first thread is adding elements to end the linked list while the second is removing them from the front. Can this be done without a lock on the linked list head when elements are beingadded/removed?
I think this lock is causing a performance hit to my application. If there isnt any safe way without it then thats fine but just thought I would check.The first thread uses this fuction to add elements to the list. Full source here. [URL]
Code:
/* Lets add the new packet to the queue. */ pthread_mutex_lock(&workers[queuenum].queue.lock); // Grab lock on queue. if (workers[queuenum].queue.qlen == 0){ // Check if any packets are in the queue.
This array is supposed to contain 12 elements (names of the month) What I want to achieve is that depending on some user input (a number 1-12) a full name of one of the months will be displayed, eg.
Code: scanf("%d", &month); printf("The month is %c", months_names[month]);
I have a text file from which i read a number of names with their lengths at the run-time.Now i want to created a char array having the length and name as already read from the text file at the run-time. There is no compilation involved. Every thing is happening at the run-time. I tried using STL like map along with malloc but i am unable to name an array at run-time. I can keep some type of mapping with previously created arrays
I manage to write apr4sens into file,works fine.But how to write it into array,which I could later reshape and so on. I tryied like this group=apr4sens. It doesn't work.
i have a loop which produces new value everytime it runs. i want to store the results in an array. how can i do dat??
loop is like: a=0 declare v while ((....)) do v[$a]="$r" let a=a+1 done
while doing this it is not treating v as array but as variable and it is overriding the value and old value is lost..i am using bash shell version 3.00.15
$1 is an argument which is actually and array. In function we want to assign a value 0 of it's first content. But it's wrong way. Anybody know the right way to assign value in function by passing as argument.
I believe I have unwanted ' characters left in a 9 element character array that are causing subsequent operations with it to fail. I see wildly differing views on the web on the proper way to flush 'em. It's clearly not as simple as it would appear at first sight. What's currently the best (or else "least deprecated") method?
Can I predefine constant array in c? with constants i do #define NAMEOFCONST value.is it possible to do this for an array? And if not I would like to know why. I suspect it has to do with memory handeling and pointers.
The idea is to make a website to check the availability of domains and it works but its not pretty yet. Below is what i have till so far:
## this is the API from my domain registrar. <?php $client = new SoapClient('http://api.sync.com/?wsdl'); ## I have a search box that sends the request to this page $var = $_GET ["s"];
## remove the most common subdomains from the request. $var=eregi_replace("www.", "", $var); $var=eregi_replace("mail.", "", $var); $var=eregi_replace("ftp.", "", $var); $var=eregi_replace("pop.", "", $var); $var=eregi_replace("smtp.", "", $var);
## remove any TLD extension from the request. $split = explode(".", $var); $main = $split[0]; $arraysize = sizeof($split); for ($x=1; $x<$arraysize; $x++) { $tld .= "." . $split[$x]; } ## login to the API $paramLogin = array('handle' => 'randall', 'password' => 'password');
Result Login: Array ( [code] => 200 [message] => Login succesful ) array(3) { ["code"]=> string(3) "200" ["message"]=> string(20) "Domain not available" ["result"]=> object(stdClass)#236 (1) { ["status"]=> string(5) "TAKEN" } } bool(true) array(3) { ["code"]=> string(3) "200" ["message"]=> string(16) "Domain available" ["result"]=> object(stdClass)#232 (1) { ["status"]=> string(4) "FREE" } } bool(true) ?> ## till so far it works
What I need to do is to make this ugly looking reply in to something more readable, basically if TAKEN print occupied and if free print its yours to grab. I have been struggling with the in_array function but i'm not getting anywhere close in getting it to work.
I was thinking about how to make a dynamic array in C, and I thought that it would be much better if it could accept any data type. Is this possible? Of course I thought about void pointers, but how do I store the actual data?
I'm trying access binary records that were created in Borland Delphi and stored in a SQL Server database (as a BLOB). What the heck is the syntax for accessing a two-D array in C#? Here's an example:
Code:
const MAX_BOWLERS = 8; gMAX_FRAMES = 40; ... type
[code]...
I've successfully got a valid "GameRec" over to C#-land. I want to access array element "GameRec.Frames[iBowler, iFrame]".
How do I define a C# type "TFrames = Array[1..Max_Bowlers, 0..gMax_Frames] of TFrame;" so that I can do it?
I have never used multidimensional array for a long time so please consider this as a newbie question. I am editing a program that uses a 4 dimensional array and I think I'm losing track of the indexes.
day = 0 to 30 hour = 0 to 23 channel = 0 to 7 len = 0 to 63 unsigned char idx[day][channel][hour][len];
I have seen that the assignment to a string is snprintf(idx[day][hour][channel], 64, "%s/%s", dayofmonth, hourofday); Is this correct? Because when I access with a day argument, that day value goes into the hour part.