PatternDB *patterndb[WORKERIDS];
int load_pattern_db(const gchar* filename, key_value_cb cb, int workerId)
{
if(patterndb[workerId] != NULL){
pattern_db_free(patterndb[workerId]);
}
patterndb[workerId] = pattern_db_new();
pattern_db_reload_ruleset(patterndb[workerId], configuration, filename);
pattern_db_set_emit_func(patterndb[workerId], pdbtool_pdb_emit_accumulate, cb);
return 0;
}
This is just the C wrapper that internally call syslog-ng methods.
Since I am using an array of patterndbs, I am calling the C code with multiple Go routines.
Single iteration of the code is working fine.
The issue is seen only with multiple go routines. Can we store the address of the C struct (when memory is allocated using calloc) on Go side in an array so that I can deallocate the memory using 'defer C.free(unsafe.Pointer(InitStruct))' when the callback is done?This should make multiple go routines to work...Am I right ?
Hi Ian,Can you please guide me with the correct way to store the address of a C struct in a Go array so that I can use it later for deallocating the memory?Thanks,Nitish
PatternDB *patterndb[WORKERIDS];
int load_pattern_db(const gchar* filename, key_value_cb cb, int workerId)
{
if(patterndb[workerId] != NULL){
pattern_db_free(patterndb[workerId]);
}
patterndb[workerId] = pattern_db_new();
pattern_db_reload_ruleset(patterndb[workerId], configuration, filename);
pattern_db_set_emit_func(patterndb[workerId], pdbtool_pdb_emit_accumulate, cb);
return 0;
}
gboolean pdbtool_accumulate_fields(NVHandle handle, const gchar *name, const gchar *value, gssize length, gpointer user_data)
{
struct Accumulatedparams *params = user_data;
key_value_cb cb = params->callback;
cb(name, value, length, params->data);
return FALSE;
}
void pdbtool_pdb_emit_accumulate(LogMessage *msg, gboolean synthetic, gpointer user_data)
{
nv_table_foreach(msg->payload, logmsg_registry, pdbtool_accumulate_fields, user_data);
}
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CALjMrq6eM1_ykJYmNVYqnFnjxqRvRCJF8Bqgh6k2N7kBV%2B_3Dw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Thanks for pointing it out.I am a beginner with Go and CGO and have never worked on corruption issues with C.I am familiar with python and Java.So just seeking help from the experts to find the pain points that should be looked into.Hence, asking questions to Ian as in where all I should look for the corruption issues.
Hi Ian,Apologies for not being very descriptive with the issue.I will try to be more clear from next time.Can you please clarify the following that you had mentioned in the previous conversation of this email:> 3)Is it possible that one Go routine has already freed up the address that the other Go routine is trying to free and that is causing this 'fatal error: bin/main': double free or corruption (fasttop)'
Yes, that is possible. It won't happen with the code I see above but
I have no idea what the rest of your code is doing.
How can it not happen with this particular code mentioned ?I did not understand this point.Can you please clarify this point ?